Re: "Default" Value In Object
Re: "Default" Value In Object
- Subject: Re: "Default" Value In Object
- From: Thaddeus Cooper <email@hidden>
- Date: Fri, 17 Jun 2005 20:57:34 -0700
Actually there is a typo in here. :-( See below for the fixed version.
--Thaddeus O. Cooper
(email@hidden)
On Jun 17, 2005, at 8:27 PM, Thaddeus Cooper wrote:
Thanks for the response Malcolm, you are a god-send. I am using an ArrayController. Using the NSPeristentDocument Core Data Tutuorial as a starting point I implemented a custom class (similar to the Employee class in the example) that looks like this:
#import "AnEntry.h"
static int tempTake = 1;
static NSString *tempScene = @"";
@implementation AnEntry
+ (void) initialize {
if (self == [AnEntry class]) {
NSArray *keys = [NSArray arrayWithObjects:
@"scene", @"take", nil];
[self setKeys:keys
triggerChangeNotificationsForDependentKey:@"updateScene"]; // <--- fixed this
}
}
- (void) awakeFromInsert {
//static int tempTake = 1;
NSString *sTake;
sTake = [[NSNumber numberWithInt:tempTake] stringValue];
[self setValue:sTake forKey:@"take"];
tempTake++;
[self setValue:tempScene forKey:@"scene"];
}
- (NSString *) updateScene {
tempScene = [[NSString alloc] initWithString:[self valueForKey:@"scene"]];
return tempScene;
}
@end
I expected that the updateScene method would get called when I changed the value in the interface, but it never gets called. I don't know if this is a totally brain-dead approach (I'm sure someone will let me know it it is). I've also tried a number of other ideas but nothing is working. Anyhow, I guess having the code may or may not help.
Thanks again.
--Thaddeus O. Cooper
(email@hidden)
On Jun 17, 2005, at 7:31 PM, mmalcolm crawford wrote:
On Jun 17, 2005, at 4:47 PM, Thaddeus Cooper wrote:
I have an entity that has several attributes. One of the attributes s starts off empty when the first object is created. When the user changes its value, in the form that should be the new value for subsequent objects. Let's say that the field is changed to 42A in the last object that was added to the graph, then until the user changes it, the subsequent values for attribute s will be 42A.
There are many different ways you could do this, depending on your application architecture.
The managed objet model is immutable after it's been used, so you can't update the default attribute value in the running application.
How are you adding new objects? If you're using an array controller, I'd consider creating a subclass of NSArrayController, setting it as the delegate of the text field, and recording user edits. Keep a record of the last value set, and set it for new objects in newObject. If this value needs to be carried over from one run of the application to another, then you could store it either in the store's metadata, or in user defaults, depending on your needs...
mmalc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden