iOS - Properties 入門

來源:互聯網
上載者:User

標籤:

iOS中,類的屬性property可以有若干個修飾詞,對應不同的屬性行為。

@property (readonly) NSString *readonly;   // 唯讀,不可修改@property (readwrite) NSString *readwrite;  // 可讀可寫,預設@property (nonatomic) NSString *nonatomic;   // 非原子操作,更快@property (atomic) NSString *atomic;        // 原子操作,預設@property (strong) NSString *strong;     // 強引用,預設@property (weak) NSString *weak;        // 弱引用,不持有對象// ARC 禁止使用retain ,與strong 一樣//@property (retain) NSString *retain;@property (assign) NSString *assign;  // 用於賦值,預設@property (copy) NSString *copys;   // copy屬性工作表示深複製,完全拷貝變數,產生新的指標,沒有copy屬性的話是淺複製,只複製變數指標,預設是淺複製

還有一些特殊的使用:

// 將getter方法更名為isFinished@property (readonly,getter=isFinished) BOOL finished;
// 自動產生getter/setter方法時,變數更名為_myFinished@synthesize finished = _myFinished;

 

iOS - Properties 入門

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.