我想存储 ABRecordRef
对象,即格式为 <CPRecord: 0xa2a3500 ABPerson>
使用 Coredata。
虽然我尝试像这样存储
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
,
reason: 'Unacceptable type of value for attribute: property = "record"; desired type = NSNumber; given type = __NSCFType; value = .
最佳答案
试试这个,
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);
关于ios - 如何在 CoreData 中存储 ABRecordRef 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21453253/