In Objective-C, given an id, how can I tell what type of object it points to?

前端 未结 4 1238
走了就别回头了
走了就别回头了 2020-12-07 19:52

Objective-C newbie question. Given the following (fictional) code:

id mysteryObject = [anotherObject mysteriousMethod];

How can I determine

4条回答
  •  [愿得一人]
    2020-12-07 20:29

    [mysteryObject class]
    

    will get you the class object. However, generally you want to do something OOPy like check for conformance to some protocol or interface.

提交回复
热议问题