views:

351

answers:

4

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.

+1  A: 

You can localize most aspects of a managed object model, including entity and property names and error messages. See here: http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/cdUsingMOM.html#//apple_ref/doc/uid/TP40005190-SW13

ctshryock
Thanks, but I'd already seen that. But that doesn't show how to localise the default value for a property. In my example it would be localising "name" rather than "Untitled"
Abizern
+1  A: 

Maybe you can localize the default values in your model (.mom file) and put the model files in the appropiate .lproj resource folders?

Diederik Hoogenboom
+1  A: 

I think awakeFromInsert is the only way

dizy
+1  A: 

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.

Ben Gottlieb