How to know the type of a variable in Objective C on Iphone?
For example if I have a function sort() like so:
+ (void) sort: (id) a { if(typeof(a) == '开发者_StackOverflowNSArray') { ... } }
So is there anything in Objective C for Iphone which can go in place of typeof() so that I can detect beforehand what kind of variable am I dealing with?
[a isKindOfClass:[NSArray class]]
Springs to mind.
I do want to point out though that in your case it makes more sense to simply type the method argument, rather than taking id and checking it's type, i.e.
+ (void)sort:(NSArray *)a
The NSObject
Protocol has comparison methods that you will be interested in.
精彩评论