0
下面是一個方法的開始,它完成了相同的操作。但是我得到一個錯誤:無法調用NSManagedObject類上的指定初始化類'汽車'初始化對象時出錯
我在做什麼錯,謝謝。
- (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"];
}