Is it safe to use isKindOfClass: against an NSString instance to determine type?

后端 未结 4 793
春和景丽
春和景丽 2020-12-02 23:14

From the isKindOfClass: method documentation in NSObject:

Be careful when using this method on objects represented by a class cluster. Because of the nature

4条回答
  •  执念已碎
    2020-12-02 23:31

    You are reading the warning wrong. All it says is that, just because it is internally represented as something that is mutable, does not mean you should try to mutate it, because mutating it could violate the contract between you and whomever you got the array from; it might violate their assumptions that you will not mutate it.

    However, the test given by isKindOfClass: is definitely still valid. If [something isKindOfClass:[NSMutableArray class]], then it is an instance of NSMutableArray or subclass thereof, which pretty much means it's mutable.

提交回复
热议问题