iOS isKindOfClass 和 isMemberOfClass 之间的区别

标签 ios objective-c swift class inheritance

Swift 中的 isKind(of aClass: AnyClass)isMember(of aClass: AnyClass) 函数有什么区别?

Objective-C 中的原始问题

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.

最佳答案

isKindOfClass:如果接收者是指定类的实例或任何类的实例,则返回YES 继承指定类的类。

isMemberOfClass: 当且仅当接收者是指定类的实例时,才返回 YES

大多数时候,您希望使用 isKindOfClass: 来确保您的代码也适用于子类。

NSObject Protocol Reference更多地讨论这些方法。

关于iOS isKindOfClass 和 isMemberOfClass 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6840849/

相关文章:

View 中的 IOS Swift 3 UILabels 无法正确渲染

ios - 如何使自定义 MKAnnotation 可拖动

objective-c - ios 13 - 带有 UISearchBar _searchField 的自定义 SearchBar 不工作

ios - Alamofire - NetworkReachabilityManager 不适用于 .notReachable

swift - AWS Amplify/iOS SDK 教程缺少步骤

ios - 访问单例中的非可选属性时出现无法解释的崩溃

iOS - 从系统设置运行应用深层链接

ios - 向 UIView 添加多个 subview

objective-c - XCode部署错误: 'NSInvalidArgumentException' , Could not find a storyboard named 'MainStoryboard'

ios - SceneKit通过特定索引有选择地为面部着色