Check whether an object is an NSArray or NSDictionary

前端 未结 4 619
慢半拍i
慢半拍i 2021-02-01 13:28

As per subject, how can I check whether an object is an NSArray or NSDictionary?

4条回答
  •  温柔的废话
    2021-02-01 14:04

    Try

    [myObject isKindOfClass:[NSArray class]]
    

    and

    [myObject isKindOfClass:[NSDictionary class]]
    

    Both of these should return BOOL values. This is basic use of the NSObject method:

    -(BOOL)isKindOfClass:(Class)aClass
    

    For a bit more information, see this answer here: In Objective-C, how do I test the object type?

提交回复
热议问题