How can I code a custom init for NSManagedObject subclass? I would like something like initItemWithName:Volume: for instance. Where Item is a NSManagedObject subclass with two attributes, name and volume.
How can I code a custom init for NSManagedObject subclass? I would like something
Share
Carlos,
As Nenad Mihajlovic suggested you could create a category for this.
So, for example, if you have an
Itemclass, you could create a category calledItem+Managementand put the creation code there. Here you can find a simple example.When you want to create a new Item, do an import like
and use like this
This approach is very flexible and very easy to maintain during the app developing.
You can find further info at Stanford Course Lecture 14 code sample. In addition, see also free videos on iTunes by Stanford (if you have an Apple ID).
Hope that helps.
P.S. For the sake of simplicity, I suppose
nameis aNSStringandvolumeis aNSNumber. Forvolumeit could be better to useNSDecimalNumbertype.