Sending a message to a Toll free bridge

2013-11-25 Thread Gerriet M. Denkmann
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?

Gerriet.



___

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

Re: Sending a message to a Toll free bridge

2013-11-25 Thread Stephen J. Butler
I don't believe that the array that CTFontCopyAvailableTables() returns
contains CFTypes. So yes, CFArray is bridgeable. But in this case that
isn't so useful since the values aren't.


On Mon, Nov 25, 2013 at 3:23 AM, Gerriet M. Denkmann
gerr...@mdenkmann.dewrote:

 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?

 Gerriet.



 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@gmail.com
___

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

Re: Sending a message to a Toll free bridge

2013-11-25 Thread Jean-Daniel Dupas

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