Skip to content

Commit

Permalink
初始化和 dealloc 第一部分
Browse files Browse the repository at this point in the history
Signed-off-by: 庞博 <[email protected]>
  • Loading branch information
庞博 committed Apr 24, 2015
1 parent ee0f018 commit 6da5898
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions translation/5-类.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ There is another good practice that you might want to follow while choosing the
另一个类的命名规范:当你创建一个子类的时候,你应该把说明性的部分放在前缀和父类名的在中间。举个例子:如果你有一个 `ZOCNetworkClient` 类,子类的名字会是`ZOCTwitterNetworkClient` (注意 "Twitter" 在 "ZOC" 和 "NetworkClient" 之间); 按照这个约定, 一个`UIViewController` 的子类会是 `ZOCTimelineViewController`.


## Initializer and dealloc 初始化和释放
## Initializer and dealloc 初始化和 dealloc

The recommended way to organize the code is to have `dealloc` method placed at the top of the implementation (directly after the `@synthesize` and `@dynamic` statements) and the `init` should be placed directly below the `dealloc` methods of any class. In case of multiple initializer the designated initializer should be placed as first method, because is the one where most likely there is more logic, and the secondary initializers should follow.

推荐在有 `dealloc` 方法的代码里面,把它放在实现的顶部。(直接在 `@synthesize` 以及 `@dynamic` 之后) 并且 `init` 应该放在 `dealloc` 之后。在多个初始化方法的类中 designated initializer 应该放在第一个,因为这样逻辑性更好,并且 secondary initializer 在之后紧随。
推荐的代码组织方式:将 `dealloc` 方法放在实现文件的最前面(直接在 `@synthesize` 以及 `@dynamic` 之后)`init` 应该放在 `dealloc` 之后。如果有多个初始化方法, designated initializer 应该放在第一个,secondary initializer 在之后紧随,这样逻辑性更好

In these days with ARC, it is less likely that you will need to implement the dealloc method, but still the rationale is that by having the dealloc very close to your init methods, you are visually emphasizing the pairing between the methods. Usually in the dealloc method you will undo things that you have done in the init methods.

在有 ARC 的日子下,你几乎不需要实现 dealloc 方法,但是关于dealloc的基本原理和 init 方法很像。你应该在方法中进行显示地强调,同时在 dealloc 中,你需要取消执行在 init 方法做的事情。
如今有了 ARC,你几乎不需要实现 dealloc 方法,但是关于dealloc的基本原理和 init 方法很像。你应该在方法中进行显示地强调,同时在 dealloc 中,你需要取消执行在 init 方法做的事情。


`init` methods should be structured like this:
Expand Down

0 comments on commit 6da5898

Please sign in to comment.