Core Data cannot resolve faults when object has “description” attribute?

后端 未结 3 359
离开以前
离开以前 2021-01-21 01:39

Code:

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

NSEntityDescription *entity = [NSEntityDescription entityForName:@\"A\"
                             


        
相关标签:
3条回答
  • 2021-01-21 02:21

    For custom descriptions you are welcome to override -(NSString *)debugDescription from NSObject Protocol. From Apple's doc:

    NSObject implements this method by calling through to the description method. Thus, by default, an object’s debug description is the same as its description. However, you can override debugDescription if you want to decouple these.

    0 讨论(0)
  • 2021-01-21 02:22

    From Core Data Programming Guide

    You are discouraged from overriding description—if this method fires a fault during a debugging operation, the results may be unpredictable—and initWithEntity:insertIntoManagedObjectContext:. You should typically not override the key-value coding methods such as valueForKey: and setValue:forKeyPath:.

    -description is a method in NSObject that returns a string representation of your object. In the line NSLog(@"%@", object), -description is used to get the string that you see in the console. Key-value coding will end up using the method to get the property for the description attribute. This causes a whole lot of confusion to Core Data.

    The programming guide is being generous when it says "discouraged". They really mean "Yeah, it's going to break your stuff."

    That link also has a good list of other methods that will break your stuff if you override them.

    0 讨论(0)
  • 2021-01-21 02:38

    you need to treat description as a reserved word. That is the issue you are having. You should have received a warning when you tried to have a property called description.

    0 讨论(0)
提交回复
热议问题