出于某种原因,我遇到了崩溃(如下所述),说“收集< __ NSCFString:0x155cefd0>在枚举时发生变异”,但仅限于实际设备上。它适用于Xcode测试设备。我不完全确定这意味着什么,所以我如何处理这个lldb崩溃?
ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, nil);
ABRecordRef pet = ABPersonCreate();
ABRecordSetValue(pet, kABPersonFirstNameProperty, (__bridge CFStringRef)petFirstName, nil);
ABRecordSetValue(pet, kABPersonLastNameProperty, (__bridge CFStringRef)petLastName, nil);
ABMutableMultiValueRef phoneNumbers = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(phoneNumbers, (__bridge CFStringRef)petPhoneNumber, kABPersonPhoneMainLabel, NULL);
ABRecordSetValue(pet, kABPersonPhoneProperty, phoneNumbers, nil);
ABAddressBookAddRecord(addressBookRef, pet, nil);
NSArray *allContacts = (__bridge NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBookRef);
for (id record in allContacts){
ABRecordRef thisContact = (__bridge ABRecordRef)record; //*******The line below is where the crash is occurring*********
if (CFStringCompare(ABRecordCopyCompositeName(thisContact),
ABRecordCopyCompositeName(pet), 0) == kCFCompareEqualTo){
//The contact already exists!
//detects if duplicate
return;
}
}
答案 0 :(得分:0)
您正在更改应用程序的其他位置的集合。根据Apple docs
"在通过它进行枚举时删除,替换或添加可变集合的元素并不安全"
请检查以下内容: