iOS new Keywords nonnull, nullable and other related

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.