Re: Problem with NSPersistentStore
Re: Problem with NSPersistentStore
- Subject: Re: Problem with NSPersistentStore
- From: Mike Abdullah <email@hidden>
- Date: Sun, 17 Feb 2013 13:45:11 +0000
Thinking about it more, your method doesn't really make sense. In order to use a context it must be associated with a persistent store coordinator, in order to know its model. So it doesn't make sense to create the coordinator lazily. Instead, make *adding the store* be the lazy bit
Sent from my iPad
On 16 Feb 2013, at 19:06, Laurent Daudelin <email@hidden> wrote:
> Hey Mike.
>
> No assertions have ever been fired, which I thought was weird a bit as well. BTW, this is on iOS, not Mac OS X if that makes any difference.
>
> -Laurent.
> --
> Laurent Daudelin
> AIM/iChat/Skype:LaurentDaudelin http://www.nemesys-soft.com/
> Logiciels Nemesys Software email@hidden
>
> On Feb 16, 2013, at 02:00, Mike Abdullah <email@hidden> wrote:
>
>>
>> On 16 Feb 2013, at 00:37, Laurent Daudelin <email@hidden> wrote:
>>
>>> I got a few crash reports from users that have a problem with my CoreData app.
>>>
>>> Given the following code:
>>>
>>> /*
>>> Returns the persistent store coordinator for the application.
>>> If the coordinator doesn't already exist, it is created and the application's store added to it.
>>> */
>>> - (NSPersistentStoreCoordinator *)persistentStoreCoordinator
>>> {
>>> if (_persistentStoreCoordinator == nil) {
>>> NSURL *storeUrl = [NSURL fileURLWithPath:self.persistentStorePath];
>>> _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[NSManagedObjectModel mergedModelFromBundles:nil]];
>>> NSError *error = nil;
>>> NSPersistentStore *persistentStore = [_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&error];
>>> NSAssert3(persistentStore != nil, @"%s at %d: Unhandled error adding persistent store: %@", __FUNCTION__, __LINE__, [error localizedDescription]);
>>> NSLog(@"Created persistent store '%@' at URL %@", persistentStore, storeUrl);
>>> }
>>> return _persistentStoreCoordinator;
>>> }
>>>
>>> When the MOC tries to perform a save, an exception is generated:
>>>
>>> Exception reason
>>>
>>> This NSPersistentStoreCoordinator has no persistent stores. It cannot perform a save operation.
>>>
>>> Stacktrace
>>>
>>> PRIMARY THREAD THREAD 0
>>>
>>> • 0 CoreFoundation 0x356212a3 __exceptionPreprocess + 163
>>> • 1 libobjc.A.dylib 0x3393197f objc_exception_throw + 31
>>> • 2 CoreData 0x36f2dfef -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 299
>>> • 3 CoreData 0x36f862d3 -[NSManagedObjectContext save:] + 731
>>>
>>> How can the persistent store not being existing?
>>
>> Well you whacked in some assertions that failures never happen (generally a bad idea for disk access. It *is* going to fail sometime). Have those assertions fired?
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden