标签:
Obj-C中没有包得概念,使用前缀进行区分
1 @implementation Car 2 - (void) run 3 { 4 NSLog(@"车子跑起来"); 5 } 6 7 @end 8 9 int main() 10 { 11 Car *c = [Car new];//创建对象,分配内存空间 12 c->wheels = 4; 13 c->speed = 250; 14 NSLog(@"车子有%i个轮子,时速是%i", c->wheels, c->speed); 15 [c run]; 16 17 return 0; 18 }
1 @interface Student : NSObject 2 { 3 int age; 4 } 5 //‘-‘ is used to define dynamic method, ‘+‘ is used to define static method 6 - (int) getAge; 7 - (void) setAge:(int)age; 8 @end
1 #import "Student.h" 2 3 @implementation Student 4 - (int) getAge 5 { 6 return age; 7 } 8 - (void) setAge:(int)newAge 9 { 10 age = newAge; 11 } 12 @end
标签:
原文地址:http://www.cnblogs.com/wvqusrtg/p/4501361.html