我得到一个null结果
AppDelegate.h
@property (readonly,strong,nonatomic) NSManagedObjectContext *managedObjectContext; @property (readonly,nonatomic) NSManagedObjectModel *managedObjectModel; @property (readonly,nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
AppDelegate.m
@synthesize managedObjectContext = __managedObjectContext; @synthesize managedObjectModel = __managedObjectModel; @synthesize persistentStoreCoordinator = __persistentStoreCoordinator; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { Person *newPerson = [NSEntityDescription insertNewObjectForEntityForName:@"Person" inManagedObjectContext:self.managedObjectContext]; ....... }
我有一个xcdatamodeld文件,其实体为Person,属性为name.我从NSManagedObject创建了一个Person.h和.m文件.
为什么我的输出结果为null.
Terminating app due to uncaught exception 'NSInvalidArgumentException',reason: '+entityForName: nil is not a legal NSManagedObjectContext parameter searching for entity name 'Person''