Re: NSArrayController: delay in setting selection, inserting item?
Re: NSArrayController: delay in setting selection, inserting item?
- Subject: Re: NSArrayController: delay in setting selection, inserting item?
- From: Joshua Scott Emmons <email@hidden>
- Date: Sun, 26 Jun 2005 16:08:34 -0400
NSManagedObject *managedObject = [NSEntityDescription
insertNewObjectForEntityForName:@"MyEntity" inManagedObjectContext:
[self managedObjectContext]];
[managedObject setValue:[NSDate
dateWithNaturalLanguageString:@"now"] forKey:@"completed"];
[NSDate date] would be more efficient than using
dateWithNaturalLanguageString: (moreover the latter may not work if
the user's preferred language is something other than English...).
Ooo! Yeah, good point!
Do you want the completed attribute to be set for every new
MyEntity object, or is this a special case? If the former, then
you should override awakeFromInsert.
Ok, but what if I want to insert a value that can only be determined
by the state of the view at run time?
Let's say I have two buttons used to insert an entry, one called "Add
Yesterday" with a tag of 0, and one called "Add Today" with a tag of 1.
I can't think of a way to put functionality like this:
-(IBAction)addBillable:(id)sender{
NSManagedObject *managedObject = [NSEntityDescription
insertNewObjectForEntityForName:@"Billable" inManagedObjectContext:
[self managedObjectContext]];
if(0 == [sender tag]){
[managedObject setValue:yesterdaysDate forKey:@"myDate"];
}else if(1 == [sender tag]){
[managedObject setValue:todaysDate forKey:@"myDate"];
}
}
into awakeFromInsert, because awakeFromInsert has no knowledge of the
sender -- or anything in the view for that matter.
Thank you for your help so far! I'd be grateful for any further advice,
-Joshua Emmons
_______________________________________________
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