Can't set default value of string property to "" in the Xcode CoreData model designer
Posted
by
glenc
on Stack Overflow
See other posts from Stack Overflow
or by glenc
Published on 2011-03-01T12:47:49Z
Indexed on
2011/03/01
15:24 UTC
Read the original article
Hit count: 349
I have an entity in my datamodel with a string property that is currently optional, and I'd like to convert this property to a required property with a default value of the empty string.
As others have discovered, leaving the default value blank results in validation errors (since the designer interprets this as NULL), but trying '', "", or @"" as the default value results in those literal characters being interpreted as the default, rather than the empty zero-length string, as desired.
I did find this thread on Google, however, apart from the solution being really ugly (model definition split between the .xcdatamodel and objc source), it also doesn't work for lightweight migrations because those migrations are done solely based on the .xcdatamodel files and the objc logic from your entity implementations isn't loaded.
Is there any way to achieve this in the data model designer?
© Stack Overflow or respective owner