What would cause persistentStoreForURL: to return nil?
I know that the URL is valid and it's readable. I can open the file in my application. I can read it into an NSData with dataWithContentsOfURL: The purpose of what I am doing is trying to migrate to an XML store to see if that will help me isolate the problem I am having with save as, which I posted about before. Here's what I do in my test in my persistent document: NSPersistentStoreCoordinator *psc = [[self managedObjectContext] persistentStoreCoordinator]; NSURL *oldURL = [NSURL fileURLWithPath:@/Users/gideon/Development/TestNMDocs/Untitled11.nm5]; NSURL *newURL = [NSURL fileURLWithPath:@/Users/gideon/Development/TestNMDocs/Untitled11.xml]; NSError *error; NSPersistentStore *myStore = [psc persistentStoreForURL:oldURL]; NSPersistentStore *xmlStore = [psc migratePersistentStore:myStore toURL:newURL options:nil withType:NSXMLStoreType error:error]; oldURL is verifiably present, readable and valid, but myStore is always nil. Any ideas? Thanks Gideon___ 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 arch...@mail-archive.com
Re: What would cause persistentStoreForURL: to return nil?
What if you print out [psc persistentStores] ? I think you'll find the PSC is surprisingly fussy about the URLs. e.g. capitalisation seems to matter. So do trailing slashes. Oh, and also the difference between: file:///foo.bar file://localhost/foo.bar On 12 Mar 2010, at 15:48, Gideon King wrote: I know that the URL is valid and it's readable. I can open the file in my application. I can read it into an NSData with dataWithContentsOfURL: The purpose of what I am doing is trying to migrate to an XML store to see if that will help me isolate the problem I am having with save as, which I posted about before. Here's what I do in my test in my persistent document: NSPersistentStoreCoordinator *psc = [[self managedObjectContext] persistentStoreCoordinator]; NSURL *oldURL = [NSURL fileURLWithPath:@/Users/gideon/Development/TestNMDocs/Untitled11.nm5]; NSURL *newURL = [NSURL fileURLWithPath:@/Users/gideon/Development/TestNMDocs/Untitled11.xml]; NSError *error; NSPersistentStore *myStore = [psc persistentStoreForURL:oldURL]; NSPersistentStore *xmlStore = [psc migratePersistentStore:myStore toURL:newURL options:nil withType:NSXMLStoreType error:error]; oldURL is verifiably present, readable and valid, but myStore is always nil. Any ideas? Thanks Gideon___ 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/cocoadev%40mikeabdullah.net This email sent to cocoa...@mikeabdullah.net ___ 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 arch...@mail-archive.com
Re: What would cause persistentStoreForURL: to return nil?
Ah, I think I had a fundamental misunderstanding - I thought it would load the store, but it only returns it if it's already loaded in the coordinator. The documentation gives no clue of this - all it says is: Parameters URL An URL object that specifies the location of a persistent store. Return Value The persistent store at the location specified by URL. I think it would be very easy to assume (as I did) that it would load it from the URL provided. Anyway, I have it working now, only it shows that I still get the same over-releasing of the managed object context when I try to migrate it to an xml store, as what I get when I try to do a save as. I'm not sure exactly what that tells me though - probably that it's a problem somewhere in my managed objects. I'll go back again and have yet another look at every place I refer to the managed object context, and see if I can track it down. rant (3am style :-)If I had had any inkling of the problems and development overheads we would have with core data when I started this, I would never have used it - I hope it does pay off in the future to make development and maintenance easier, but for the moment, it's been a massive and unexpected investment./rant Thanks for your help Mike. Regards Gideon On 13/03/2010, at 2:09 AM, Mike Abdullah wrote: What if you print out [psc persistentStores] ? I think you'll find the PSC is surprisingly fussy about the URLs. e.g. capitalisation seems to matter. So do trailing slashes. Oh, and also the difference between: file:///foo.bar file://localhost/foo.bar ___ 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 arch...@mail-archive.com
Re: What would cause persistentStoreForURL: to return nil?
On 12 Mar 2010, at 16:48, Gideon King wrote: Ah, I think I had a fundamental misunderstanding - I thought it would load the store, but it only returns it if it's already loaded in the coordinator. The documentation gives no clue of this - all it says is: Parameters URL An URL object that specifies the location of a persistent store. Return Value The persistent store at the location specified by URL. I think it would be very easy to assume (as I did) that it would load it from the URL provided. I think the use of for is supposed to be your hint there. Cocoa uses it almost universally to mean that the returned object is already present and that you're doing nothing more than a lookup. -persistentStoreWithURL: would be more like you expected I think.___ 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 arch...@mail-archive.com