Le 25 nov. 2013 à 10:23, Gerriet M. Denkmann <gerr...@mdenkmann.de> a écrit :

> The documentation states: "CFArray is “toll-free bridged” with its Cocoa 
> Foundation counterpart, NSArray. This means that the Core Foundation type is 
> interchangeable in function or method calls with the bridged Foundation 
> object. Therefore, in a method where you see an NSArray * parameter, you can 
> pass in a CFArrayRef"
> 
> Does this also mean: "any message you can send to an NSArray, you can send 
> also to an CFArrayRef"?
> 
>       NSFont *fo = [ NSFont fontWithName: @"Thonburi" size: 0 ];
>       CTFontRef font = (__bridge CTFontRef)fo;
>       CFArrayRef tags = CTFontCopyAvailableTables ( font, 0 );
>       NSArray *tagsArray = CFBridgingRelease(tags);
>       // next  line prints: class __NSCFArray count: 18
>       NSLog(@"%s class %@ count: %lu",__FUNCTION__, [tagsArray class], 
> [tagsArray count]);
> 
> So sending messages to an CFArrayRef seems to be ok. Or not?
> 
> But then this line crashes:
> 
>       NSString *tagDescription = [ tagsArray description ];
> 
> My mistake? My false assumption?

You just hit a corner case. Toll free bridging is supported only for 
collections of objects compatible with id. 
CTFontCopyAvailableTables() is one of the very few API that returns a 
CFArrayRef that contains plain int value, and so cannot be safely converted to 
NSArray.

An other well known corner case is when you try to cast a CFMutableDictionary 
into a NSMutableDictionary. The later requires that key are copyable objects 
while the former support other types of keys.

Except such cases, you should be able to call any NSArray method on a 
CFArrayRef.

-- Jean-Daniel





_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to