类:动物(动物),这个词就是类。对象:一条狗(具体的某只)(狗),一只乌龟(乌龟),一只兔子(兔子)方法:跑步跑,,,乌龟,狗64公里,25.2米,兔子36公里
<人力资源/>定义一个类:
1。# import & lt;基?Foundation.h> 2.@ interface动物:NSObject 3. 4. - (void) run_speed; 5. - (void) set_speed: (int) n; 6.@end
1。@ implementation动物 2 . { 3.int速度; 4 .} 5. 6. - (void) run_speed 7 . { 8. NSLog(@“运行速度%我”,速度); 9。} 10. - (void) set_speed: n (int) 11。{ 12. 速度=n; 13。} 14.@end
使用代码:
1. int主要(int命令行参数个数,char * argv []) 2 . { 3.@autoreleasepool { 4. 动物*狗; 5. 6. 狗=[动物alloc]; 7. 狗狗=(init); 8. 9. (狗set_speed: 64); 10。(狗run_speed); 11. 12. } 13. 14. 返回0; 15. 16.}
iOS开发之objective - c:类,对象和方法