Search code examples
ioscore-datacore-data-migrationxcdatamodel

iOS xcdatamodel newly added attribute has quotation mark


I just migrated my new data model and added a new attribute called "author_mail".However I discover at when I output my records:

attachments = "<relationship fault: 0xd2459c0 'attachments'>";
author = nil;
"author_mail" = nil; <-- ABNORMAL
category1 = World;

I set the author_mail to string type but I don't think the author_mail should wrap with quotation mark. I don't know if it related to my migration but it does not output any error. Any clue where should I start look on? I found nothing on the internet.

Result I want:

attachments = "<relationship fault: 0xd2459c0 'attachments'>";
author = nil;
author_mail = nil; 
category1 = World;

Thanks everyone.


Solution

  • That's not abnormal, and it does not mean what you think it means. Relax, nothing is wrong.

    What you're seeing is the result of calling description on NSManagedObject. By default, this is how NSManagedObject formats the result. If a key name contains any non-alphanumeric characters, it puts quote marks around the key name. That's just how they decided to do it. As a result:

    • This only affects the result of calling description on the object, which is what happens if you call NSLog to print the object.
    • This does not indicate that the quote marks are part of the key name. If you try to set a value for author_name, you'll find that you should not include the quotes, because they're not part of the name.

    This has no effect on anything aside from printing the objects using the description method.

    You can and should just ignore this.

    If it really bothers you for some reason, create your own subclass of NSManagedObject and override the description method. Make it print whatever you want, with whatever formatting you want.