• 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: Toll-free bridge type at runtime
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Toll-free bridge type at runtime


  • Subject: Re: Toll-free bridge type at runtime
  • From: Marcel Weiher <email@hidden>
  • Date: Thu, 2 Apr 2009 17:06:37 -0700


On Apr 2, 2009, at 16:43 , Chris Suter wrote:

On Fri, Apr 3, 2009 at 10:37 AM, Marcel Weiher <email@hidden > wrote:

So the compiler also disagrees with you that these are the same type. You
can *cast* them to be compatible, but they are not the same type.

Right, but the original question was about figuring out what they are at runtime which I don't believe is possible and it's not clear to me whether you think it is possible.

As I explained, it is trivially possible, because the only Objective-C class that is the same as its underlying CFType is NSCFArray. So a simple test would be [object class] == [NSCFArray class]. If you want to be somewhat more secure against spoofing, you can use the objc_xyz method for getting the class.


Another way to distinguish them at runtime from the C/CF side would be to use CFGetTypeID().

So as I said, they are easily distinguishable at both compile and runtime.

#import <Foundation/Foundation.h>
#import <MPWFoundation/MPWFoundation.h>

int main(int argc, char *argv[] )
{
	MPWObject *obj=[MPWObject new];
	NSArray *array=[NSArray array];
	CFArrayRef cfarray;
	id otherArray;

	cfarray=array;
	otherArray=cfarray;
	NSLog(@"mpw %d",CFGetTypeID(obj));
	NSLog(@"cf %d",CFGetTypeID(array));
}

2009-04-02 17:06:23.229 a.out[53491:10b] mpw 1
2009-04-02 17:06:23.229 a.out[53491:10b] cf 17

_______________________________________________

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


  • Follow-Ups:
    • Re: Toll-free bridge type at runtime
      • From: Chris Suter <email@hidden>
    • Re: Toll-free bridge type at runtime
      • From: Marcel Weiher <email@hidden>
References: 
 >Toll-free bridge type at runtime (From: Ryan Joseph <email@hidden>)
 >Re: Toll-free bridge type at runtime (From: Michael Ash <email@hidden>)
 >Re: Toll-free bridge type at runtime (From: Marcel Weiher <email@hidden>)
 >Re: Toll-free bridge type at runtime (From: Michael Ash <email@hidden>)
 >Re: Toll-free bridge type at runtime (From: Marcel Weiher <email@hidden>)
 >Re: Toll-free bridge type at runtime (From: Michael Ash <email@hidden>)
 >Re: Toll-free bridge type at runtime (From: Marcel Weiher <email@hidden>)
 >Re: Toll-free bridge type at runtime (From: Chris Suter <email@hidden>)

  • Prev by Date: Re: Toll-free bridge type at runtime
  • Next by Date: Re: Toll-free bridge type at runtime
  • Previous by thread: Re: Toll-free bridge type at runtime
  • Next by thread: Re: Toll-free bridge type at runtime
  • Index(es):
    • Date
    • Thread