|
|
#1 |
|
Saving nsmanagedobject context not saving
Code:
NSManagedObjectContext *ctx = [[NSManagedObjectContext alloc] init];
[ctx setUndoManager:nil];
ITMAppDelegate *appDel = (ITMAppDelegate *)[[UIApplication sharedApplication] delegate];
[ctx setPersistentStoreCoordinator: [appDel persistentStoreCoordinator]];
//self.managedObjectContext = appDelegate.managedObjectContext;
ITMDistinctCustomers *distinctCustomer = (ITMDistinctCustomers *)[NSEntityDescription
insertNewObjectForEntityForName:@"ITMDistinctCustomers"
inManagedObjectContext:ctx];
distinctCustomer.name=@"Blah";
...
[self.distinctCustomerArray addObject:distinctCustomer];
NSError *error = nil;
if (![ctx save:&error])
{
NSLog(@"Failed to save distinct customer");
}
Last edited by dejo; Jan 24, 2013 at 07:03 PM. Reason: Please use proper [code] tags. |
|
|
|
0
|
|
|
#2 |
|
How do you know it won't save? What debugging have you done? What, if any, has it shown?
__________________
|
|
|
|
0
|
|
|
#3 |
|
@dejo.I have this tool called SQLite Manager, a firefox addon.In that tool I went to the ITMDistinctCustomers table and did "select * from ITMDistinctCustomers "and it has nothing in there.
Last edited by RookieAppler; Jan 25, 2013 at 08:35 PM. Reason: some information |
|
|
|
0
|
|
|
#4 |
|
Did you check what the NSError returns?
__________________
|
|
|
|
0
|
|
|
#5 |
|
I wonder if the problem is that you're not passing the baton. You seem to be creating a new baton out of thin air in the hands of the second runner and trying to bless it as the official baton.
A quick read of the doc's and sure you can attach multiple MOC's to the same PersistentStoreCoordinator but the store uniques between the contexts. I sort of wonder if the uniquing is obscuring the created objects. Are there and objects in the file? If your going to the appDelegate to get the PersistentStoreCoordinator anyway why not just ask it for the ManagedObjectContext instead?
__________________
There is no such thing as "Collective Wisdom" [13" MacBookPro 2.7Ghz, 27"Al iMac i7, Black MacBook 13", iPhone 4, iPad] |
|
|
|
0
|
![]() |
|
| Tags |
| ios, not working, nsmanagedobjectcontext, save |
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 02:56 AM.







I support the 
Linear Mode
