我正在使用核心数据来保存数据。我的应用程序第一次保存数据时没有任何问题,但第二次应用程序在[self.managedObjectContext save:nil];
崩溃日志中在线崩溃
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber localizedCaseInsensitiveCompare:]: unrecognized selector sent to instance 0x98dda90'
*** First throw call stack:
(0x1e6e012 0x179ee7e 0x1ef94bd 0x1e5dbbc 0x1e5d94e 0xeeae92 0xf645ee 0x15ca8f5 0x15c5785 0x15c8061 0xf53dc9 0x1ec80c5 0x1e22efa 0xe88482 0x14da5f3 0x1573e5f 0x14d5a26 0x14d916e 0x77ca 0x7d4e 0x17b2705 0x3dd920 0x619b24 0x17b2705 0x3dd920 0x3dd8b8 0x49e671 0x49ebcf 0x49dd38 0x40d33f 0x40d552 0x3eb3aa 0x3dccf8 0x1dc9df9 0x1dc9ad0 0x1de3bf5 0x1de3962 0x1e14bb6 0x1e13f44 0x1e13e1b 0x1dc87e3 0x1dc8668 0x3da65c 0x3efd 0x2425)
libc++abi.dylib: terminate called throwing an exception
我正在使用以下代码来保存数据
- (IBAction)save:(id)sender {
Projects *projects = [NSEntityDescription insertNewObjectForEntityForName:@"Projects" inManagedObjectContext:self.managedObjectContext];
NSLog(@"object id %@", projects.objectID);
projects.title = projectTitleTxtFld.text;
projects.descProject = descriptionTxtView.text;
projects.type = projectType.text;
projects.recID = [self generateRandom];
NSLog(@"rec id %@", projects.recID);
[self.managedObjectContext save:nil]; //here my app crashes
NSLog(@"title %@", projects.title);
}
-(NSNumber*)generateRandom
{
int number = arc4random();
if (number < 0) {
number = number * -1;
}
NSNumber *newNumber = [NSNumber numberWithInt:number];
return newNumber;
}