CoreData Model Objects for API

Posted by theiOSguy on Stack Overflow See other posts from Stack Overflow or by theiOSguy
Published on 2012-04-14T05:23:00Z Indexed on 2012/04/14 5:29 UTC
Read the original article Hit count: 168

Filed under:
|

I am using CoreData in my application. I want to abstract out all the CoreData related stuff as an API so that the consume can use the API instead of directly using CoreData and its generated model objects. CoreData generates the managed objects model as following

@interface Person : NSManagedObject

@end

I want to define my API for example MyAPI and it has a function called as

createPerson:(Person*)p;

So the consumer of this createPerson API needs to create a Person data object (like POJO in java world) and invoke this API. But I cannot create Person object using

Person *p = [Person alloc] init]

because the designated initializer for this Person model created by CoreData does not allow this type of creation.

So should I define corresponding user facing data object may be PersonDO and this API should take that instead to carry the data into the API implementation?

Is my approach right? Any expert advise if design the API this way is a good design pattern?

© Stack Overflow or respective owner

Related posts about core-data

Related posts about model