标签:
1.http://www.cnblogs.com/mjios/archive/2013/04/06/3002814.html
2.How to create a oc class?
3.
3.1 In which two files? What did they create for?
3.2 How to judge a function is static or dynamic?
3.3成员变量的常用作用域有3种?
3.4 How to write in .h file?(no member)
3.5 How to write in .m file?(no member)
3.6With one member variable.(.h statement)
3.7With one member variable.(.m realization)
3.8 Create object.(In main)
------------------
Answer
2. 2.1 XCode new file-> OS X .cocoa oc-class->name+NSObject
2.2 .h statement
2.3 .m realization
2.4 main() create object
3.1 .h .m
3.2 +static(class) -dynamic(object)
3.3 @public @private @protected
3.4
#import <Foundation/Foundation.h>
@interface Student : NSObject
@end
3.5
#import "Student.h" @implementation Student @end
3.6
#import <Foundation/Foundation.h> @interface Student : NSObject { int age; // 年龄 } @end
#import <Foundation/Foundation.h> @interface Student : NSObject { int age; // 年龄 @public int no; // 学号 int score; // 成绩 @protected float height; // 身高 @private float weight; // 体重 } // age的get方法 - (int)age; // age的set方法 - (void)setAge:(int)newAge; @end
- (void)setAge:(int)newAge andHeight:(float)newHeight;
3.7
#import "Student.h" @implementation Student // age的get方法 - (int)age { // 直接返回成员变量age return age; } // age的set方法 - (void)setAge:(int)newAge { // 将参数newAge赋值给成员变量age age = newAge; } // 同时设置age和height - (void)setAge:(int)newAge andHeight:(float)newHeight { age = newAge; height = newHeight; } @end
3.8
#import <Foundation/Foundation.h> #import "Student.h" int main(int argc, const char * argv[]) { @autoreleasepool { Student *stu = [[Student alloc] init]; [stu release]; } return 0; }
标签:
原文地址:http://www.cnblogs.com/yesihoang/p/4444843.html