Folks;

I have a CoreData model working reasonably under Tiger now moving to aggressive testing on Leopard.

I'm seeing something I don't believe I've never seen on Tiger...

The application has only one ManagedObjectContext. This is established during the -awakeFromNib of the NSApp delegate. Any other class which deals with the data does so by invoking [[NSApp delegate] managedObjectContext].

I have a popup menu that controls a primary selection for the user which restricts which objects are displayed currently. Life is good. Change the popup selection --> see a different list of objects!.

There is a reasonably complex set of preferences which is managed by a single window with a toolbar and swapping in/out tabViews. Nothing too outrageous but when the user closes this window I'm doing a save on the MgdObjCtx:

 (void) windowWillClose:(NSNotification *)notice {
        NSManagedObjectContext *moc = [[NSApp delegate] managedObjectContext];
        NSError *error = nil;
        if ([moc commitEditing]) {
                if ([moc hasChanges])  {
                        if (![moc save:&error]) {
NSLog(@"Error while saving\n%@", ([error localizedDescription] != nil) ? [error localizedDescription] : @"Unknown Error");
                        }
                }
        } else {
                //MOC CommitEdit problem ...
        }
}

I can change the popup's selection while the pref window is open and all is well, but as soon as I close the window I get a failure.
If I comment out the MgdObjCtx handling above, everything works fine.
So should I just let it go and trust CoreData? But my brain wants to understand and my paranoia says I'm better off getting it written on the disk....

The popup uses a fetchRequst to populate an array.
After closing the pref window (and thereby invoking the save above) the MgdObjCtx is still valid and the fetchReques is found and instantiated but the results are (null) whereas immediately before closing the window the results would have populated an array.

I know I must be missing some key aspect of save but I am seriously stumped here.

Thanks for any thoughts,
Steve

+ (ObjX *)lookupByName:(NSString *)name inContext: (NSManagedObjectContext *)moc {
        NSError *error = nil;
        NSArray *results = nil;
        @try {
NSFetchRequest * fReq = [[[moc persistentStoreCoordinator] managedObjectModel] fetchRequestFromTemplateWithName:@"findByObjXName" substitutionVariables:[NSDictionary dictionaryWithObject:name forKey:@"name"]];
                results = [moc executeFetchRequest:fReq error:&error];
                }


Before Window Closes:
2008-04-24 02:20:19.315 ABC[1427:10b] [ObjX lookupByName:inContext:] moc = <NSManagedObjectContext: 0x221bb30> 2008-04-24 02:20:19.316 ABC[1427:10b] [ObjX lookupByName:inContext:] fReq = <NSFetchRequest: 0x25b0b60> (entity: ObjX; predicate: (ObjXName == "Test Pilots"); sortDescriptors: (null); limit: 0) 2008-04-24 02:20:19.339 ABC[1427:10b] [ObjX allMembersForObjXNamed:inContext:] this ObjX = < ObjX: 0x24e4260> (entity: ObjX; id: 0x24a4af0 <x-coredata://A882A39C- .......

After Window Closes:
2008-04-24 02:20:36.147 ABC[1427:10b] [ObjX lookupByName:inContext:] moc = <NSManagedObjectContext: 0x221bb30> 2008-04-24 02:20:36.148 ABC[1427:10b] [ObjX lookupByName:inContext:] fReq = <NSFetchRequest: 0x297dd00> (entity: ObjX; predicate: (ObjXName == "Test Pilots"); sortDescriptors: (null); limit: 0) 2008-04-24 02:20:36.151 ABC[1427:10b] [ObjX allMembersForObjXNamed:inContext:] thisGroup = (null)


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to