Q:

Custom NSManagedObject subclass constructor

I have a question about CoreData and NSManagedObject. 
In the architecture of my application I have a REST client That builds instances of objects That I receive from the server.
For example I have this method: 
- (NSArray*) getAllCards:(NSDictionary*) jsonResponse;

That takes the JSON response and returns an array of Cards. 
It's ok ... 
Now I need to save my Card in CoreData. 
I defined my model so I have some subclass of NSManagedObject. 
For example: Card: NSManagedObject 
but I would like to have a simple constructor to construct the object from the JSON and then pass this to my manager who will add it in CoreData. 
I would not pass some info related to CoreData (eg. Context ..) to my Client REST ... I would like to have the logic in my CoreData CoreData Manager .. 
How can I define a valid constructor of my Cards? 
Can I define a constructor in this way?
- (id) initWithName:(NSString*) name
             cardId:(NSString*) cardId
         type:(NSString*) type
{
    self = [super initWithEntity:nil insertIntoManagedObjectContext:nil]; //This is wrong..
    if (self) {
        self.name = name;
        self.cardId = cardId;
        self.type = type;
    }
}

A:

I see no need to override the init methods. Just give your CoreDataManager class a method that takes the dictionary and generates the core data entities.
-(void)storeCardsFromJSON:(NSDictionary*)dictionary {
   for (NSDictionary *cardInfo in dictionary[@"cardArray"]) {
       Card *newCard = [NSEntityDescription insert...];
       newCard.cardID = cardInfo[@"cardID"];
       // etc.
   }
   // save
}

Optionally, return an array of newly created cards. In this method you could also filter out the cards that already exist (e.g. based on the cardID attribute) and modify those instead of inserting them again.  
In your app, you should only use the Card objects from Core Data. There is no need to have a different class of objects, or use NSDictionary objects.

