Nonnull: cannot be null (used to modify a property, a method parameter, or a method return value)

Code:

@property (nonatomic, copy, nonnull) NSString *name; @property (nonatomic, copy) NSString * _Nonnull name; @property (nonatomic, copy) NSString * __nonnull name; @property (nonatomic, assign) NSUInteger age; @property (nonatomic, assign) NSUInteger age; // All attributes wrapped in the following macro have the nonnull property. If you don't want to have this property, you can define it yourself. // Between NS_ASSUME_NONNULL_BEGIN and NS_ASSUME_NONNULL_END, all object attributes and methods defined are nonNULL by defaultCopy the code

// Can also be used when defining methods

- (nonnull NSString *)test:(nonnull NSString *)name; - (NSString * _Nonnull)test1:(NSString * _Nonnull)name;Copy the code

This way, you will get this effect prompt when using the above method

Similarly, when using attributes:

Nullable = null; nullable = null;

Code (for a general look, refer to the above) :

@property (nonatomic, copy, nullable) NSString *name; @property (nonatomic, copy) NSString *_Nullable name; @property (nonatomic, copy) NSString *__nullable name;Copy the code

Effect:

In this way, when using the property, Xcode’s code prompt will tell you that the property can be null, which is a kind of programming specification to reduce communication between programmers.

3, null_resettable: get: not return empty, the set can be null (note: if you use null_resettable, must be rewritten the get method or set methods, treatment in the case of the value that is empty)

// How to write:

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

Set the set or get method

- (void)setName:(NSString *)name {if (name == nil) {name = @" I am changmin "; } _name = name; The name {} - (nsstrings *) if (_name = = nil) {_name = @ "my name is chang min"; } return _name; }Copy the code
_Null_unspecified: It is uncertain whether the value is unspecified

There are only two ways to use it:

@property (nonatomic, strong) NSString *_Null_unspecified name;

@property (nonatomic, strong) NSString *__null_unspecified name; 
Copy the code

Summary: I understand that the main purpose of these things is to improve the development specification, to remind users of what values should be passed, and to warn them if they violate the specification values.

// New iOS9 keywords: used to modify properties, or method parameters, method return value // benefits: // 1. Cater to SWIFT // 2. Improve our developer development standards and reduce communication between programmers

Nullable can only modify objects. Nullable cannot modify basic data types