【发布时间】:2011-09-28 12:46:16
【问题描述】:
我需要检查一个对象是否是 NSNotification。仅仅知道它是否是子类是不够的,因为我想区分它是 NSNotification 还是 NSNotification 的子类。
所以要详细说明,我需要区分以下几点:
- NSConcreteNotification
- NSNotification 的子类(但不是 NSConcreteNotification)
问题是 NSNotifications 实际上是 NSConcreteNotifications 而 NSConcreteNotification 是一个私有类,所以我不能用它来测试。
[object isMemberOfClass: [NSNotification class]] // returns NO in both cases
[object isKindOfClass: [NSNotification class]] // returns YES in both cases
【问题讨论】:
-
您测试的对象是 NSNotification no 的子类?
-
你可以使用objective-C的isMemberOfClass方法。请参考[isMemberOfClass][1][1]:stackoverflow.com/questions/2045561/…
-
对象可以是 1. NSConcreteNotification 或 2. NSNotification 的子类。我需要区分。
-
我已更新问题以澄清。
标签: objective-c ios nsnotification