According to the docs:
You should not override init. You are discouraged from overriding initWithEntity:insertIntoManagedObjectContext:
and you should instead use awakeFromInsert or awakeFromFetch.
This is fine if all I want to do is set some attribute to the current date or similar, but what if I want to send in another object and set attributes based on its information?
For example, in an NSManagedObject subclass called 'Item', I want an initFromOtherThing:(Thing *)thing, in which the item's name is set to that of the thing. I would like to avoid 'just having to remember' to set the name each time immediately after creating the item, and having to update fifteen different controller classes when I decide that I want Item to also set another default attribute based on Thing. These are actions tied to the model.
How am I meant to handle this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…