PDA

View Full Version : How to check if an object is NSObject or CFTypeRef




namanhams
Aug 1, 2012, 03:48 AM
I have an object of type (id). This object is either a ABRecordRef, or an instance of a class that is subclass of NSObject.

How do i determine the real type of this object ?
Thanks.



solderguy1
Aug 1, 2012, 04:01 AM
I'd say look into these three
isa field
isKindOfClass
respondsToSelector

Reason077
Aug 1, 2012, 05:08 AM
ABRecordRef is a C type - it should not be stored in the ObjC type "id"!

Normally, if you want to test if an ObjC object is a particular class, you do it like the following:

"if ([obj isKindOfClass: [MyObjCClass class]]) ..."

But again, you should not be calling isKindOfClass (or any other ObjC method) on an instance of ABRecordRef - it is not an ObjC type.