objective-c 基础语法和习题 / self 的用法
2014-03-12 11:51
260 查看
观察下面这段代码和以前代码的区别,主要是看self ; 一般self 是代表当前 对象。
1.#import <Foundation/Foundation.h> 2. 3.@interface Animal: NSObject 4. 5.@property int Speed, Legs; 6. 7.-(void) display; 8. 9.-(void) set_speed:(int) speed o:(int) legs ; 10. 11.@end 12. 13.@implementation Animal 14. 15.@synthesize Speed,Legs; 16. 17.-(void) display 18.{ 19. NSLog(@"run speed %i",Speed); 20. NSLog(@"I have %i legs",Legs); 21.} 22. 23.-(void) set_speed:(int) speed o: (int) legs 24.{ 25. Speed = speed; 26. Legs = legs; 27. [self display]; 28.} 29.@end 30. 31. 32.int main(int argc, const char * argv[]) 33.{ 34. 35. @autoreleasepool { 36. Animal *dog; 37. 38. dog = [Animal alloc]; 39. dog = [dog init]; 40. 41. 42. [dog set_speed:30 o: 4]; 43. 44. 45. Animal * rabbit = [[Animal alloc] init]; 46. 47. [rabbit set_speed:56 o:4]; 48. 49. 50. // insert code here... 51. NSLog(@"Hello, World!"); 52. 53. } 54. return 0; 55.}
相关文章推荐
- objective-c 基础语法和习题 / 类 详解/ 函数多参数的几种用法
- objective-c 基础语法和习题 :类、对象和方法
- objective-c 基础语法和习题 /类 详解/ . 属性的方法
- IOS开发Objective-C基础之—self.用法
- IOS开发Objective-C基础之—self.用法
- 【IOS】objective-c 基础语法和习题一
- objective-c 基础语法和习题 / 类 详解
- ios-基础用法之【2】-Objective-c 语法,类/属性/函数
- objective-c 基础语法和习题 / 类 详解/合成存取
- expect语法基础: while、for 循环、if 语句的用法示例
- 黑马程序员——IOS学习之二:Objective-C基础语法和关键字——黑马 ios 技术博客
- IOS学习之二:Objective-C基础语法和关键字
- Objective-C基础语法快速入门
- Objective-C(四、属性声明与功能,点语法)——iOS开发基础
- objective-c 关于self的用法总结
- objective-c基础语法学习之--(7)拷贝对象
- [Objective-c 基础 - 2.2] OC弱语法、类方法
- Objective-C 基础语法log打印那些事儿(一)
- 总结一些Objective-C的self.用法
- Objective-C的self.用法的一些总结