iOS在isKindOfClass和isMemberOfClass之间的区别 [英] iOS difference between isKindOfClass and isMemberOfClass
问题描述
isKindOfClass:(Class)aClass
和isMemberOfClass:(Class)aClass
函数之间有什么区别?
我知道这有点小,一个是全局的,另一个是完全匹配的类,但是我需要有人指定哪个是哪个.
What is the difference between the isKindOfClass:(Class)aClass
and the isMemberOfClass:(Class)aClass
functions?
I know it is something small like, one is global while the other is an exact class match but I need someone to specify which is which please.
在Swift isKind(of aClass: AnyClass)
和isMember(of aClass: AnyClass)
中.
推荐答案
isKindOfClass:
返回YES
从指定类继承的任何类的实例.
isKindOfClass:
returns YES
if the receiver is an instance of the specified class or an instance of any class that inherits from the specified class.
isMemberOfClass:
仅在接收者是指定类的实例的情况下返回YES
.
isMemberOfClass:
returns YES
if, and only if, the receiver is an instance of the specified class.
大多数时候您想使用isKindOfClass:
来确保您的代码也可用于子类.
Most of the time you want to use isKindOfClass:
to ensure that your code also works with subclasses.
NSObject协议参考详细讨论这些方法.
这篇关于iOS在isKindOfClass和isMemberOfClass之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!