On Apr 3, 2009, at 9:17 AM, Ali Ozer wrote:

One point of the discussion is that there is no need to do this, and things you think you might want to do the test for are probably invalid.

But, if you wanted to test, you could see if the instance you have isKindOfClass:[NSCFArray class]. However, this would be fragile, since "NSCFArray" is not in the public API, and just an implementation detail. You could try something like

CFArrayRef cfArray = CFArrayCreate(NULL, NULL, 0, &kCFTypeArrayCallBacks); // Create a temp CFArray
 Class cfArrayClass = [(id)cfArray class];      // Get its class
 CFRelease(cfArray);
return ([array isKindOfClass: cfArrayClass]); // See if your array happens to be an instance of the same class (or is a subclass)

...but even this may be fragile and not guaranteed to get you the result you were expecting. I'd really recommend finding a solution that doesn't require this test. The transparency of toll-free bridging should be enough for almost anything you need to do with CF or NSArrays "on the other side." (Except for those CFArrays which were created with custom callbacks, which should never be treated as NSArrays.)

Greg Guerin said it right. ;)

I think I need explain what exactly I need this for. I'm making a Pascal bridge to Cocoa and it would be convenient if I could pass a CF type or a Pascal wrapper indiscriminately and decide at runtime how they should handled. If I knew the type was CF (thus NOT a wrapper, because it was created from a CoreFoundation function) I would not dereference the object and cause crashing.

People are having a more abstract debate on this then is necessary I think, almost like a show of object-oriented prowess. What I'm really asking is there a way to know where they ORIGINATED from, CoreFoundation API or Cocoa. I said clever because there must be some sub-standard way to get this info, as this is a sub-standard situation.

Thank you Ali, I will look this over and see what it yields. You may be right however this is not safe.



Ali


On Apr 2, 2009, at 6:27 PM, Greg Guerin wrote:

Despite each side presenting its own test that proves its own case, may I suggest answering the OP's question:

http://lists.apple.com/archives/cocoa-dev/2009/Apr/msg00082.html

The conditions seem pretty clear to me.

Last one to the garden gate is a rotten egg. ;-)

-- GG


Regards,
        Josef

_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Reply via email to