Core data attribute not being made
I've decided to add an NSNumber attribute to one of my entities in core data. I Cleaned the code and deleted the app from the simulator. I then added the following code in my appDelegate and it tells me that my NSNumber attribute doesn't exist.
People *PeopleA = [NSEntityDescription insertNewObjectForEntityForName:@"People" inManagedObjectContext:context];
PeopleA.name = @"Paul";
PeopleA.number = [NSNumber numberWithInt:12];
The name attribute works just fine, that was made before and it's always worked. But when it gets to PeopleA.number
it crashes with :
-[People setNumber:]: unrecognized selector sent to instance 0x4d5eeb0
So I did a po 0x4d5eeb0
and saw that there is a name attribute but not one for number. My core data class should be good because I had XCode make it for me.
What could possibly be the issue?
Here is my People.h
#import <Foundat开发者_JS百科ion/Foundation.h>
#import <CoreData/CoreData.h>
@class Group;
@interface People : NSManagedObject {
@private
}
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) id image;
@property (nonatomic, retain) NSNumber * number;
@property (nonatomic, retain) Group * group;
@end
People.m
#import "People.h"
#import "Group.h"
@implementation People
@dynamic name;
@dynamic image;
@dynamic number;
@dynamic group;
@end
po 0x4d5eeb0 gets me:
<People: 0x5932290> (entity: People; id: 0x59322f0 <x-coredata:///People/t83A9C7D9-4F7A-4189-9EC5-7695968A29552> ; data: {
group = nil;
name = Paul;
Printing the object in the debugger should give you all the properties defined in the class regardless of whether it is a NSManagedObject subclass held by a context or just a plain vanilla custom class. The debugger printout is not only missing the number
property but the image
one as well.
Really, the only way that could happen was if you didn't have the new version of the class file added to the target but were actually using the old version that lacked the new properties.
Check the target for the old files and/or check that the new version has been properly added to the build target.
Try naming the number
attribute something different, such as theNumber
. There are several known reserved words in Core Data attributes, and an unknown number (no pun intended) which are not documented - you may have stumbled onto another one.
When in doubt, delete it out.
I ended up deleting my two xcdatamodel files and the xcdatamodeld file. Also deleted them in their respective folders. Then I created a new one. Had some issues at first but it actually works now.
I have a little issue with xcode thinking that my Group.h
file doesn't have an addPeople
method, which it does. So it says that it may not respond to that method, or any of its other methods. It also throws me a Lexical or Preprocessor Issue: 'Group.h' file not found
error at build-time, but everything seems to still work.
I still have no idea what was going on. Thanks to everyone for their suggestions.
精彩评论