• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Sending a message to a Toll free bridge
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sending a message to a Toll free bridge


  • Subject: Re: Sending a message to a Toll free bridge
  • From: Jean-Daniel Dupas <email@hidden>
  • Date: Mon, 25 Nov 2013 14:29:38 +0100

Le 25 nov. 2013 à 10:23, Gerriet M. Denkmann <email@hidden> 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 (email@hidden)

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:

This email sent to email@hidden


References: 
 >Sending a message to a Toll free bridge (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: CVPixelBufferCreateWithPlanarBytes does not execute callback when released
  • Next by Date: Re: iOS screen physical size (or px density)
  • Previous by thread: Re: Sending a message to a Toll free bridge
  • Next by thread: iOS screen physical size (or px density)
  • Index(es):
    • Date
    • Thread