bobo思密达

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

1.如何定义一个OC的类

@interface 类名:父类名

{

//实例变量(不建议写在.h文件中,写在.m的extension中)

//假如子类要继承的时候,必须写在.h中

}

@property

方法

@end

2.属性和实例变量

属性是一组getter和setter

3.初始化方法

-(id/instancetype)initWithXXX

指定初始化方法

4.便利构造器

特殊的初始化方法,实现了alloc 和 autorelese(方便内存管理)

5.Category

分类,扩展类。比较牛逼的存在。

语法格式

@interface 类名 (分类名)

@end

@implementation 类名 (分类名)

@end

6.一个OC类(Cup)

 

//

//  CUP.h

//  CUP

//

//  Created by Carl_fang on 15/3/2.

//  Copyright (c) 2015年 Carl_fang. All rights reserved.

//

#import <Foundation/Foundation.h>

 @interface CUP : NSObject

 @property (nonatomic) float price;

 - (instancetype) initWithVolume:(NSInteger) volume brand:(NSString *)brand;

 +(CUP *)cupWithVolume:(NSInteger) brand:(NSString *)brand;

 - (void) fillInWater:(NSInteger)volume;

@end

7.内存管理

重点:引用计数

autorelese

 

posted on 2015-03-02 11:41  bobo思密达  阅读(121)  评论(0)    收藏  举报