码迷,mamicode.com
首页 > 其他好文 > 详细

1.1 OC class new summary

时间:2015-04-21 17:24:49      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

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;
}

  

1.1 OC class new summary

标签:

原文地址:http://www.cnblogs.com/yesihoang/p/4444843.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!