+ (void)initialize vs 静态构造方法

在继承体系中,多个子类的引用,父类缺省执行一次;

特殊情况:

1)子类没有实现、调用父类方法;

2)子类显示调用父类;

3)存在分类实现,分类实现覆盖本体。

 

Initializes the class before it receives its first message.

The runtime sends initialize to each class in a program just before the class, or any class that inherits from it, is sent its first message from within the program. Superclasses receive this message before their subclasses.

The runtime sends the initialize message to classes in a thread-safe manner. That is, initialize is run by the first thread to send a message to a class, and any other thread that tries to send a message to that class will block until initialize completes.

The superclass implementation may be called multiple times if subclasses do not implement initialize—the runtime will call the inherited implementation—or if subclasses explicitly call [super initialize]. If you want to protect yourself from being run multiple times, you can structure your implementation along these lines:

posted @ 2018-02-01 15:37  zzfx  阅读(125)  评论(0编辑  收藏  举报