iOS SDK 4.3 学习笔记 iPhone101 (01)
2011-05-23 14:51
405 查看
准备 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; // 直接访问成员变量
一篇小小的 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; // 直接访问成员变量
相关文章推荐
- iOS SDK 4.3 ( Xcode 4 )学习笔记 iPhone101 (05)
- iOS SDK 4.3 学习笔记 iPhone101 (02)
- iOS SDK 4.3 学习笔记 iPhone101 (03)
- iOS SDK 4.3 学习笔记 iPhone101 (04)
- 新浪微博iOS版SDK“宝玉XP”框架学习笔记
- ios学习笔记(一)Windows7上使用VMWare搭建iPhone开发环境
- iOS新手学习第一天 学习笔记 iPhone的第一个程序
- ios学习--iphone开发笔记和技巧总结(原址持续更新)
- IOS 学习笔记17 iPhone开发之使用NSUserDefaults存储数据
- ios学习笔记之UI篇(四):美化按钮使其看起来具有iphone风格
- IOS学习笔记1—Iphone程序运行流程
- iOS学习笔记01-APP相关
- iOS音频学习笔记二:iOS SDK中与音频有关的相关框架
- iOS学习笔记01——在工程中实现ARC和MRC混合编译
- Programming in Objective-C 学习笔记10——Cocoa, Cocoa Touch and the iOS SDK
- Object-C 学习笔记(IOS程序设计课程)01
- iOS学习笔记01_内存管理的整理
- ios学习笔记-01-UIView
- iOS学习笔记01-APP相关
- IOS学习笔记1—Iphone程序运行流程