我想使用Coredata以ABRecordRef
的格式存储<CPRecord: 0xa2a3500 ABPerson>
对象。
虽然我试图像
NSEntityDescription *entityDescriptionStrings = [NSEntityDescription entityForName:@"ContactsStrings" inManagedObjectContext:context];
ContactsStrings *contactsManagedObjectStrings = [[ContactsStrings alloc] initWithEntity:entityDescriptionStrings insertIntoManagedObjectContext:context];
ABRecordRef recordRef = CFArrayGetValueAtIndex(contactInfoArray, i);
[contactsManagedObjectStrings setValue:(__bridge id)(recordRef) forKey:@"record"];
我崩溃了
记录我已作为Integer32数据类型。
由于未捕获的异常
NSInvalidArgumentException
终止了应用程序,原因:“属性:属性=的值的不可接受类型
“记录”;所需类型= NSNumber;给定类型= __NSCFType;值=
。
最佳答案
尝试这个,
ABRecordRef recordRef = CFArrayGetValueAtIndex(contactInfoArray, i);
ABRecordId recId = ABRecordGetRecordID(recordRef);
NSNumber *recordId = [NSNumber numberWithInt:(int)recId];
[contactsManagedObjectStrings setValue:recordId forKey:@"record"];
找回
//recordId is the value of record key from managedobject
ABRecordId recId = (ABRecordId)[recordId intValue];
ABRecordRef recordRef = ABAddressBookGetPersonWithRecordID(ddressBook, recId);