Keywords in objective-c

Source: Internet
Author: User
first, the support of nullability detection 1. IntroductionIn the previous OC, the development often encountered because a method should return an instance object and actually returned empty caused the application to crash, and Nullability's usefulness is here, it can prompt the developer to make a decision whether empty. In IOS 9, new keywords are presented: nullable, Nonnull, null_resettable, _null_unspecified; Note: The above keywords can only be used to modify OC objects and cannot be decorated with basic data types
2. NullableFunction: Can be empty notation:

Notation 1

@property (Nonatomic, Strong, Nullable) NSString * name_1;

Notation 2

@property (nonatomic, Strong) NSString * __nullable name_2;

Notation 3

@property (nonatomic, Strong) NSString * _nullable name_3;


3. nonnull function: Can not be empty notation:

Notation 1

@property (Nonatomic, Strong, nonnull) NSString * name_1;

Notation 2

@property (nonatomic, Strong) NSString * __nonnull name_2;

Notation 3

@property (nonatomic, Strong) NSString * _nonnull name_3;

Note: Between Ns_assume_nonnull_begin and Ns_assume_nonnull_end, all defined objects and methods default to Nonnull


4. null_resettable Function: Getter method cannot return null; Setter method can be written as follows:

@property (Nonatomic, Strong, null_resettable) NSString * name_1; Note: If you use Null_resettable, you must override the getter or setter method
5. Null_unspecified Effect: Unsure whether an empty notation:

Notation 1

@property (nonatomic, Strong) NSString * __null_unspecified name_1;

Notation 2

@property (nonatomic, Strong) NSString * _null_unspecified name_2;
two, type wildcard characters 1. In the program often meets with ObjectType, it is neither a type nor a keyword, just a type wildcard
third, __kindof function: Indicates the current class or its subclasses write:

__kindof classname *


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.