I have a coredata entity named Record and has a property dateUpdated. I noticed that the generated NSManagedObject subclass has no optional mark (?)
CoreData Editor:
Generated Subclass:
Expected:
UPDATED:
It's tedious in my part, because each time I want to regenerate the subclasses, it means I also need to update all optional values manually. Having a non-optional (without '?') in subclass lead me to check evalue before assigning, like example below:
// sample value:
// serverDateFormatter = "yyyy/MM/dd"
// dateString = ""
// Branch is a subclass of Record (see above images)
var date = self.coreData.serverDateFormatter.dateFromString(dateString)
if date != nil
{
branch.dateUpdated = date
}
But if xcode can automatically set optional value in subclass with (?) I just need to do like this:
branch.dateUpdated = self.coreData.serverUTCDateFormatter.dateFromString(dateString)
In my case, I have bunch of properties I need to mark as optional manually.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…