Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 24, 2013, 05:47 PM   #1
RookieAppler
macrumors member
 
Join Date: Mar 2012
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");
	}
I make an NSMutableArray of distinctCustomers and try to save them but it wont save. I put only this entity here. I have 10 other entities and neither saves. Please help me out. Thanks.

Last edited by dejo; Jan 24, 2013 at 07:03 PM. Reason: Please use proper [code] tags.
RookieAppler is offline   0 Reply With Quote
Old Jan 24, 2013, 07:06 PM   #2
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by RookieAppler View Post
I make an NSMutableArray of distinctCustomers and try to save them but it wont save.
How do you know it won't save? What debugging have you done? What, if any, has it shown?
__________________
dejo is offline   0 Reply With Quote
Old Jan 25, 2013, 08:28 PM   #3
RookieAppler
Thread Starter
macrumors member
 
Join Date: Mar 2012
@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
RookieAppler is offline   0 Reply With Quote
Old Jan 25, 2013, 09:37 PM   #4
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Did you check what the NSError returns?
__________________
dejo is offline   0 Reply With Quote
Old Jan 25, 2013, 10:06 PM   #5
MattInOz
macrumors 68030
 
MattInOz's Avatar
 
Join Date: Jan 2006
Location: Sydney
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"
[ iPhone 5s, iPad Mini, 13" MacBookPro 2.7Ghz, 27"Al iMac i7, Black MacBook 13"]
MattInOz is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Tags
ios, not working, nsmanagedobjectcontext, save

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
All iPads: Saving to cloud Jake789 iPad 3 Dec 31, 2013 07:45 PM
Help saving an old CD Rom rei101 Mac Applications and Mac App Store 8 May 15, 2013 06:09 PM
Saving Mechanism ahan.tm Mac Programming 0 Apr 24, 2013 09:11 PM
New words not saving Lefo iOS 6 0 Mar 4, 2013 07:14 PM
10.8.1 and saving location Dr. Beast OS X 10.8 Mountain Lion 2 Aug 24, 2012 01:13 AM

Forum Jump

All times are GMT -5. The time now is 11:14 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC