iOS9新特性之常見關鍵字、泛型

來源:互聯網
上載者:User

標籤:nat   get   取出   ble   ios開發   spec   資料   郵件   方法   

 

#pragma mark -- nullable


nullable:可以為空白,只能修飾對象,不能修飾基礎資料型別 (Elementary Data Type)
// 方式一:
@property (nonatomic, copy, nullable) NSString *name;
// 方式二:
@property (nonatomic, copy) NSString *_Nullable name;
// 方式三:
@property (nonatomic, copy) NSString *__nullable name;

 

// 方法中
- (nullable NSString *)test:(nullable NSString *)str;
- (NSString * _Nullable)test1:(NSString * _Nullable)str;

 

#pragma mark -- nonnull

 

 

nonnull: 不可為空,只能修飾對象,不能修飾基礎資料型別 (Elementary Data Type)

// 方式一:
@property (nonatomic, copy, nonnull) NSString *name;
// 方式二:
@property (nonatomic, copy) NSString * _Nonnull name;
// 方式三:
@property (nonatomic, copy) NSString * __nonnull name;

// 方法中
- (nonnull NSString *)test:(nonnull NSString *)str;
- (NSString * _Nonnull)test1:(NSString * _Nonnull)str;

#pragma mark -- null_resettable

 

 

null_resettable: get:不能返回為空白, set可以為空白

@property (nonatomic, copy, null_resettable) NSString *name;


// 注意;如果使用null_resettable,必須 重寫get方法或者set方法,處理傳遞的值為空白的情況


#pragma mark -- _Null_unspecified

 

 _Null_unspecified:不確定是否為空白

方式一
@property (nonatomic, copy) NSString *_Null_unspecified name;
方式二
@property (nonatomic, copy) NSString *__null_unspecified name;

 

#pragma mark -- 泛型

 

@property (nonatomic, strong) NSMutableArray<NSString *> *arrayM;

// 表明arrayM數組中存放的對象只能是NSString類型的對象

// 開發規範、從數組中取出來對象,直接當做泛型對象使用,可以直接使用點文法,提高開發效率

 

 

#pragma mark -- __kindof

 

// __kindof Person *:表示傳回值可以是Person類或者它的子類,外面使用的時候可以很清楚的知道傳回值的類型

+ (__kindof Person *)person;

 

 

有任何關於iOS開發的問題!歡迎下方留言!!!或者郵件[email protected] 雖然我不一定能夠解答出來,但是我會請教iOS開發高手!!!解答您的問題!!!

iOS9新特性之常見關鍵字、泛型

聯繫我們

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