I am getting an error:

Implicit conversion of C pointer type 'ABRecordRef' (aka 'const void *') to Objective-C pointer type 'id' requires a bridged cast

from this code, trying to add an ABRecordRef to an NSMutableArray

ABRecordRef person = (__bridge ABRecordRef)[contactArr objectAtIndex:i];
[addressBookArray addObject:person];

addressBookArray is defined as

NSMutableArray *addressBookArray;
有帮助吗?

解决方案

As the error message says, you need to re-cast the object in order to put it back into an NSMutableArray:

ABRecordRef person = (__bridge ABRecordRef)[contactArr objectAtIndex:i];
[addressBookArray addObject:(__bridge ABRecord *)person];

ABRecord is the ObjC class that corresponds to ABRecordRef; they're toll-free bridged, so they are interchangeable for this purpose.


Note: ABRecord is only available on OS X. If you're on iOS and somehow managed to get those ABRecordRefs into an NSArray in the first place, you'll have to use id for the re-cast

[addressBookArray addObject:(__bridge id)person];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top