how can you find out if an NSObject has a certain property?

前端 未结 1 1412
孤城傲影
孤城傲影 2021-02-19 11:08

Let\'s say in Apple API version 1.0, there is a class NSFoo with a property \'color\'. API 1.1 adds property \'size\'.

I want to know whether I can use the getter: myFo

1条回答
  •  不要未来只要你来
    2021-02-19 11:52

    You're close. Your selector should be exactly the message you want to send to the object:

    if ( [myFoo respondsToSelector:@selector(size)] ) {
        int size = [myFoo size]; // or myFoo.size in dot-notation.
        // ...
    }
    

    should work.

    0 讨论(0)
提交回复
热议问题