How to tell if a Class inherits from NSObject (Objective-C)

前端 未结 4 1004
小鲜肉
小鲜肉 2021-01-06 12:29

I\'m working in Objective-C on the iPhone and need to know whether a \'Class\' inherits from \'NSObject\'.

I tried checking if it responds to an NSObject selector:

4条回答
  •  不思量自难忘°
    2021-01-06 12:55

    respondsToSelector: is itself an NSObject-defined selector, so you can't use it. I don't believe there's a way to do this without getting very deep into the internals of Objective-C.

    May I ask why you have objects that aren't descendants of NSObject? Apple very strongly recommends you don't attempt to create them, and with good reason.

提交回复
热议问题