1, nonnull: literal meaning can know: can not be empty (used to modify the properties, or the parameters of the method, the return value of the method)
Code:
1 //three ways to use2@property (nonatomic, copy, nonnull) NSString *name;3 4@property (nonatomic, copy) NSString *_nonnull name;5 6@property (nonatomic, copy) NSString *__nonnull name;7 8 //Supplement (not applicable to the Assign attribute, as it is specifically used to modify pointers)9 @property (nonatomic, assign) Nsuinteger age;Ten One //Add (the properties wrapped with the following macros all have nonnull characteristics, of course, if one of the properties you do not want to have this feature, you can also define yourself, such as adding a nullable) A //between Ns_assume_nonnull_begin and Ns_assume_nonnull_end, all of the object properties and methods defined are nonnull by default
1 // can also be used when defining a method 2 // neither the return value nor the parameter can be empty 3 -(nonnull NSString *) Test: (nonnull nsstring *) name; 4 // Ibid . 5 -(NSString * _nonnull) Test1: (NSString * _nonnull) name;
This way, you will be prompted with this effect when you use the above method
Again, when using attributes:
2.Nullable: Indicates that it can be empty (using the same method as above, but no macro similar to the one found above)
Code (probably look at it, refer to it above the line):
1 // three ways to use 2 // Way One: 3 @property (nonatomic, copy, nullable) NSString *name; 4 // Way Two: 5 @property (nonatomic, copy) NSString *_nullable name; 6 // Way Three: 7 @property (nonatomic, copy) nsstring *__nullable name;
Effect:
This way, when using this property, Xcode's code hints will tell you that this property can be empty, a programming specification, and less communication between programmers.
3.Null_resettable:get: cannot return null , set can be empty ( Note: If you use null_resettable, you must override the get method or set method to handle the case where the value passed is empty)
How to write :
1 @property (nonatomic, copy, null_resettable) NSString *name;
Setting the set or Get method
1- (void) SetName: (NSString *) name2 {3 if(Name = =Nil) {4Name =@"My name is Chang min .";5 }6_name =name;7 }8-(NSString *) name9 {Ten if(_name = =Nil) { One_name =@"My name is Chang min ."; A } - return_name; -}4._null_unspecified: Not sure whether it is empty
There are only two ways to use it:
1 @property (nonatomic, Strong) NSString *_null_unspecified name;
1 @property (nonatomic, strong) NSString *__null_unspecified name;
Summary: I understand these things mainly in order to improve the development of norms, to indicate what kind of people to use the value, if the violation of the standard value of the requirements, there will be a warning;
Several new keywords for iOS9 (nonnull, Nullable, Null_resettable, __null_unspecified)