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

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

Code:

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

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


        
3条回答
  •  醉话见心
    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.

提交回复
热议问题