ios - 如何在 CoreData 中存储 ABRecordRef 对象

标签 ios iphone core-data nsmanagedobjectcontext

我想存储 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/

相关文章:

cocoa - 核心数据迁移一对多关系

objective-c - 设置重用同一对象的核心数据关系会删除以前的关系

ios - 在后台线程上保存数据时收到内存警告

ios - Ionic 2 RC3 iOS 8 自定义字体字母间距问题

iPhone + UITableView + 放置图像作为分隔符

iphone - 从新版本的应用程序中删除购买的应用程序(iOS)

iphone - 在不向右移动单元格内容的情况下显示 UITableViewCell 重新排序控件?

ios - 在 Swift 2.0 中设置 UINavigationController 栏标题

ios - 全屏 iOS 分享扩展

android - v2 API 中的 Linkedin 登录个人资料图片 URL