iOS9新特性(一)

iOS9 - 新特性

至iOS9出來到如今已有一年了,下面是我在工做中的一些總結.

iOS9新特性之關鍵字

  • iOS9新出的關鍵字:用來修飾屬性,或者方法的參數,方法的返回值
  • 好處:ios

    • 1.迎合swift(由於OC是弱語言,swift是強語言)程序員

    • 2.提升開發人員開發規範,減小程序員之間交流swift

  • 注意:
    • iOS9新出的關鍵字nonnull,nullable,null_resettable,_Null_unspecified只能修飾對象,不能修飾基本數據類型.
  • nullable做用:表示能夠爲空atom

nullable書寫規範:
 // 方式一:
 @property (nonatomic, strong, nullable) NSString *name;
 // 方式二:
 @property (nonatomic, strong) NSString *_Nullable name;
 // 方式三:
 @property (nonatomic, strong) NSString *__nullable name;
  • nonnull做用:不能爲空
nonnull: non:非 null:空

書寫格式:
 @property (nonatomic, strong, nonnull) NSString *icon;

 @property (nonatomic, strong) NSString * _Nonnull icon;

 @property (nonatomic, strong) NSString * __nonnull icon;
  • NS_ASSUME_NONNULL_BEGINNS_ASSUME_NONNULL_END之間,定義的全部對象的屬性和方法默認都是nonnullcode

  • null_resettable做用: get:不能返回爲空, set能夠爲空對象

// 書寫方式:
@property (nonatomic, strong, null_resettable) NSString *name;

 // 注意:若是使用null_resettable,必須 重寫get方法或者set方法,處理傳遞的值爲空的狀況
  • _Null_unspecified:不肯定是否爲空
書寫方式只有這種
    方式一
    @property (nonatomic, strong) NSString *_Null_unspecified name;
    方式二
    @property (nonatomic, strong) NSString *__null_unspecified name;
相關文章
相關標籤/搜索