IOS開發中訪問成員變數

來源:互聯網
上載者:User

標籤:ios   property   開發   成員變數   

在類中使用_property訪問私人成員變數是沒有問題的,使用self.property也可以,但是後者不能用在init 和 dealloc中,程式中全部使用_property這種形式會帶來微小的最佳化,雖然在我們的小程式中體現不出來。

早期的 Objective-C 語言,類的私人成員變數是只能定義在 .h 的標頭檔裡面的,後來可以加到.m檔案中,用如下形式:

@interface EverydayTVC() <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, assign) int page;

@end


後來又允許在.m中直接新增成員變數:

@implementation EverydayTVC

{

    NSInteger _num;

}

推薦用這種方法和_property訪問私人成員變數的方法。

文章參考自唐巧大神的部落格http://www.devtang.com,自己做個記錄。



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.