iOS SDK 4.3 学习笔记 iPhone101 (01)

来源:互联网 发布:生鲜app源码 编辑:程序博客网 时间:2024/05/17 16:54

准备 iPad 开发,由于使用IOS SDK 4.3 , 很多老的书的界面与此不符,只好看英文的说明了。

 

一篇小小的 HelloWorld 居然看了 n 个小时。。。。。。写了快30年程序了,实在汗颜。

 

难点有三:

1   界面不熟 (IOS SDK 4.3 变化较大)

2   语言障碍 (英语还是不如母语呀)

3   程序框架 (完全不了解)

 

打算每天写些,希望能对刚开始用IOS SDK 4.3 的同学们略有帮助。

 

https://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhone101/Articles/00_Introduction.html

iPhone101.pdf

 
P25 有这样一行语句
@synthesize myViewController=_myViewController;
 
P26 是这样说明的
You use the “_” prefix for the instance variable to serve as a reminder that you shouldn’t access an instance variable directly. From an academic perspective, this helps to preserve encapsulation, but there are two important practical benefits in Cocoa:
● Some Cocoa technologies (notably key-value coding) depend on use of accessor methods, and in the appropriate naming of the accessor methods. If you don’t use accessor methods, your application may be less able to take advantage of standard Cocoa features.
● Some property values are created on-demand. If you try to use the instance variable directly, you may get nil or an uninitialized value. (A view controller’s view is a good example.)
 
字典中 synthesize 的意思是“综合,使合成;人工合成”
 
在这里 synthesize 的作用应该是生成 get 和 set 方法。而后面的变量增加下划线只是为了在使用这个成员变量时,确保使用 get 和 set 方法,而不是直接访问。其实也可以写成:
 
@synthesize myViewController
 
不过,如果写成上面这个样子,就无法从字面上确定像以下这样的语句,调用的是 get 和 set 方法,还是直接访问成员变量了。
 
self.myViewController = aViewController;
 
如果写成 @synthesize myViewController=_myViewController; 则很容易区分。
 
self.myViewController = aViewController;      // 使用 set 方法
self._myViewController = aViewController;    // 直接访问成员变量