至iOS9出來到如今已有一年了,下面是我在工做中的一些總結.
好處:ios
1.迎合swift(由於OC是弱語言,swift是強語言)程序員
2.提升開發人員開發規範,減小程序員之間交流swift
修飾對象,不能修飾基本數據類型
.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_BEGIN
和NS_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;