下面是一个从头到尾做同样事情的方法的开始。但是我收到一个错误:无法在 NSManagedObject 类 'Car' 上调用指定的初始化程序
我做错了什么,谢谢。
- (Car*) initWithJSONData:(NSDictionary *)responseData {
BOOL isActive;
self = [super init];
Car*coreDataCar =(Car*)[NSEntityDescription insertNewObjectForEntityForName:@"Car" inManagedObjectContext:[self managedObjectContext]];
//Check if car is active or deactive.
if (![responseData valueForKeyIsNull:@"Car Status"]) {
int carStatus = [[responseData valueForKey:@"Car Status"] intValue];
if (carStatus == 1 ) {//active
isActive=YES;
}else if( carStatus == 2 ){
isActive = NO;
}
}
if (![responseData valueForKeyIsNull:@"Name"]) {
[coreDataCar setValue:[responseData valueForKey:@"Name"] forKey:@"name"];
}
NSLog(@"user count = %@",[responseData valueForKey:@"UserCount"]);//Sometimes it crashes here, others it doesnt
if (![responseData valueForKeyIsNull:@"UserCount"]) {
//[responseData valueForKey:@"UserCount"];
[coreDataCar setValue:[responseData valueForKey:@"UserCount"] forKey:@"userCount"];
}