Nullable, NULL resettable, NULL KINDOF usage in IOS generics _ios

Source: Internet
Author: User

IOS9 New Keywords: used to modify attributes, or method parameters, the return value of the method

IOS9 New Keyword Nonnull,nullable,null_resettable,_null_unspecified

One thing to be aware of is that you can only decorate objects and not modify basic data types.

Although it is not often used in code writing for a project, it is often encountered when invoking the Apple system method, which requires a summary

Nullable function: The expression can be empty

Nullable writing Specification:
//Mode one:
@property (Nonatomic, Strong, nullable) NSString *name;
Mode two:
@property (nonatomic, strong) NSString *_nullable name;
Mode III:
@property (nonatomic, strong) NSString *__nullable name;

nonnull function: cannot be empty

Nonnull:non: non-null: null
writing format:
@property (nonatomic, Strong, nonnull) NSString *icon;
@property (nonatomic, Strong) NSString * _nonnull icon;
@property (nonatomic, Strong) NSString * __nonnull icon;

Between Ns_assume_nonnull_begin and Ns_assume_nonnull_end, all object properties and methods that are defined by default are nonnull

null_resettable function: Get: Cannot return to NULL, set can be empty

Writing methods:
@property (nonatomic, Strong, null_resettable) NSString *name;
Note that if you use null_resettable, you must override the Get method or the set method to handle the case where the passed value is null

_null_unspecified: not sure if null

This is the only
way to write a
@property (nonatomic, strong) NSString *_null_unspecified name;
Mode two
@property (nonatomic, strong) NSString *__null_unspecified name;

__kindof: Represents the current class or its subclasses

__KINDOF Writing format:

Put in front of the type, indicating that the type is decorated (__kindof MyCustomClass *)

__kindof: When called, it is clear that the return type uses the __kindof-decorated class name to either represent the current class or to represent the subclass of the current class

The above is a small set to introduce the iOS generics nullable, null resettable, NULL KINDOF usage details, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

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.