How to avoid accidental overriding method or property in Objective-C

前端 未结 4 1453
轮回少年
轮回少年 2021-01-04 05:47

For instance, I subclassed UILabel and added a method or property called -verticalTextAlignment to align text vertically.
And in the future, if

4条回答
  •  爱一瞬间的悲伤
    2021-01-04 06:37

    1. Yes you could use your own prefix, however that is uncommon.

    2. Yes, it can happen after an O/S update; Objective-C is a very dynamic language where messages are sent to methods rather than being called, as in other languages. These things are worked-out at runtime, not compile time.

    Bottom line is yes, you might accidentally override a future base class method and the only solution is to be there when it happens and rename the method.

提交回复
热议问题