Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I localise the default value of attribute in a Core Data Entity

If I was creating an entity with a non-optional string attribute called, say, "name", I would put "Untitled" as the default. How could I localise this default value?

I could subclass the entity and and use NSLocalizedString in awakeFromInsert to do this. But I was wondering if there was another way.

Edit:

If this is the only way, then I'm fine with it. Just curious.

like image 746
Abizern Avatar asked Jun 10 '09 04:06

Abizern


Video Answer


2 Answers

I think awakeFromInsert is the only way

like image 51
dizy Avatar answered Nov 09 '22 17:11

dizy


You can try using -[NSEntityDescription attributesByName]. This will give you back an NSDictionary of NSAttributeDescription objects. You can then pull the one you want and use -[NSAttributeDescription setDefaultValue:] on it.

like image 24
Ben Gottlieb Avatar answered Nov 09 '22 18:11

Ben Gottlieb