문제

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