objective-c init方法的写法

来源:互联网 发布:javascript onclick 编辑:程序博客网 时间:2024/06/05 00:20

Thus, we arrive at the rules that all stylish Objective-C programmers follow when writing initializers:

  • If a class has several initializers, only one should do the real work. That method is known as the
    designated initializer. All other initializers should call, either directly or indirectly, the designated
    initializer.
  • The designated initializer will call the superclass’s designated initializer before initializing its
    instance variables.
  • If the designated initializer of your class has a different name than the designated initializer of
    its superclass, you must override the superclass’s designated initializer so that it calls the new
    designated initializer.
  • If you have several initializers, clearly document which is the designated initializer in the header.

from objective-c-programming

0 0
原创粉丝点击