1,nonnull and Nullabledeclares whether the property can be nil, and if the Nonnull property is assigned nil, a warning is reported.
1 2 3 |
@property (Nonatomic, Strong, nonnull) Nsarray *array1;
@property (nonatomic, Strong) Nsarray * __nullable array2; |
The main function is the interaction between developers, call the property can know that this property is possible nil, for this state to do some processing. By default, this is the nullable state. can be used to give the parameters of the method most requirements, such as a method, the parameter is a non-empty object:2,null_resettabledeclaring the property set method can be nil, but get must not be nil, there is a seemingly conflicting place, that is, you can define a property of nil, but when the property is obtained, this property can not be nil, otherwise there will be a warning. The place used here, for example in Uiviewcontroller view, means that the developer can assign a value of nil to the controller's view, but the controller view is lazy-loaded, and each time you get the view of the controller, you can get a non-nil view.a new feature of objective-c: nullability annotations. At the heart of this new feature are two different types of annotations:__nullable and __nonnull. We can literally guess that__nullable indicates that an object can be null or nil, while __nonnull means that the object should not be empty. When we do not follow this rule, the compiler gives a warning. but this is just a warning that the program can be compiled and run. In fact, you can use __nullable and __nonnull in any place where you can use the Const keyword, but these two keywords are limited to using pointer types. In the declaration of the method, we can also use the nullable and nonnull without the underlined
iOS new Keywords nonnull, nullable and other related