문제

I want to set up Core Data entirely programmatically. I've defined a database schema in the form of an NSManagedObjectModel and added some entity definitions in the form of NSEntityDescription's as is done at the bottom of this page. All is well with that.

I then created an NSPersistentStoreCoordinator using its class method initWithObjectModel: and passing in the aforementioned schema. At this point I don't know what to do.

I assume the next step is to somehow get an NSManagedObjectContext, because as I understand it, it's like a DB scratchpad and is required for most everything I want to eventually do (create,read,update,delete records, etc). What's the next step (keeping in mind no gui tools), and if it's getting a context, how do I do that? Also, if anyone knows any blog posts / resources for doing this sort of thing entirely programmatically, that'd be great.

도움이 되었습니까?

해결책

Here's how to setup the NSManagedObjectContext:

[[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];

A good step-by-step guide with explanation can be found here:

http://www.objc.io/issue-4/full-core-data-application.html

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top