# 08.load与-initialize

## + load

* 当类对象被引入时,runtime会向每一个类对象
* load方法会在每一个类甚至分类被引入时仅调用一次.
* 调用的顺序是:
  * 父类优先于子类,子类优先于分类
* load方法不会被自动继承
  * 子类中没有+load方法时系统不会多次调用父类+load

### 使用场景

* Method Swizzle

## + initialize

* 第一次使用这个类的时候会调用这个方法-懒加载
  * 会在第一次使用第一个类方法或实例方法之前被调用

### 使用场景

* 初始化全局变量或静态变量
* load方法会被子类/分类继承
  * 如果子类没有实现+initialize方法,会调用父类的+initialize方法


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ryukiedev.gitbook.io/wiki/ios/za-xiang/load-yu-initialize.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
