gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 03:17:57 37 4
gpt4 key购买 nike

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

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com