Reputation: 892
For example if I have a function sort() like so:
+ (void) sort: (id) a { if(typeof(a) == 'NSArray') { ... } }
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?
Upvotes: 1
Views: 898
Reputation: 5542
[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
Upvotes: 3
Reputation: 163238
The NSObject
Protocol has comparison methods that you will be interested in.
Upvotes: 1