iOS新年複習

來源:互聯網
上載者:User

標籤:

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

 

iOS新年複習

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.