@
meta 在实现的效果上我也完全找不到有什么区别了. 我也求解答!
书上和网上的例子能看出的却别也就是用法概念之类的问题..
https://developer.apple.com/library/ios/documentation/cocoa/conceptual/ProgrammingWithObjectiveC/CustomizingExistingClasses/CustomizingExistingClasses.html#//apple_ref/doc/uid/TP40011210-CH6-SW6看这个官方的例子, 实际实现效果的区别也就是只有类内部可以使用 `[self setProperty:xxx]` 或者 `self.property = xxx` 这样的用法而已.
----
* 在 @
interface 声明的 instance variable 是 protected 的.
* 在 @
implement 声明的 instance variable 是 "private" 的.
* @
synthesize 自动声明的 instance variable 也是 "private" 的.
* objective-c 里面的类方法只有两种:
** 在 @
interface 声明的. "public"
** 没在 @
interface 声明的. "private". (其实是没有这个概念的是吧?!)
所以要声明 instance variable 或者 method 为私有的(private) 的话, 根本没必要在 class extension 的声明.
----
我在 <Learning Cocoa with Objective-c> 的 `Class Extensions` 章节看到这两句话:
>
there are two reasons for extending a class:
1. You want to add extra behavior and logic to an existing class
2. You want to break up one of your own classes into separate components.
我现在能想到的就是
1. 配合 `category` 将一个大类进行各种拆分组合, 类似于 `Mixin` 的用法.
因为 `category` 可以创建方法但不能创建类变量, 而另一个则可以创建类变量但不能创建方法. 而且方法声明貌似没什么用处...
2. 将一个大类以不同的 @
interface 组合暴露出去, 按适用需要 `import` (这个貌似也很弱的样子... = =)
= =. 今天就先到这好了... 以后遇到再说...