objective c - Error trying to access iOS store -


all,

i have following code in project:

- (nspersistentstorecoordinator *)persistentstorecoordinator {     if (__persistentstorecoordinator != nil)     {         return __persistentstorecoordinator;     }     nserror *error = nil;       nsstring *storepath = [[self applicationdocumentsdirectory] stringbyappendingpathcomponent:@"my_model.sqlite"];      nsurl *storeurl = [nsurl fileurlwithpath:storepath];       __persistentstorecoordinator = [[nspersistentstorecoordinator alloc] initwithmanagedobjectmodel:[self managedobjectmodel]];     if (![__persistentstorecoordinator addpersistentstorewithtype:nssqlitestoretype configuration:nil url:storeurl options:nil error:&error])     {         nslog(@"unresolved error %@, %@", error, [error userinfo]);         abort();     }      return __persistentstorecoordinator; }  - (nsstring *)applicationdocumentsdirectory {     nserror *err = nil;     return [nsstring stringwithcontentsofurl:[[[nsfilemanager defaultmanager] urlsfordirectory:nsdocumentdirectory indomains:nsuserdomainmask] lastobject] encoding:nsutf8stringencoding error:&err]; } 

and receiving error:

* terminating app due uncaught exception 'nsinvalidargumentexception', reason: '* -[nsurl initfileurlwithpath:]: nil string parameter'

what don't understand why returning s nil? have referenced book code , seems think should work ok. ideas?

thanks in advance

paul

your -applicationdocumentsdirectory method looks strange me. instead of returning path of documents dir, try return contents of directory (which not possible read, hence return nil).

try replacing method with

- (nsurl *)applicationdocumentsdirectory {     return [[[nsfilemanager defaultmanager] urlsfordirectory:nsdocumentdirectory                                                    indomains:nsuserdomainmask] lastobject]; } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -