The distinction and use of nullable,nonnull, null_resettable and _null_unspecified

Source: Internet
Author: User

1. Keywords: can be used in attribute methods and return value parameters

Keyword action: Hint function tells developer property information

Purpose of the keyword: to cater to Swift's strong language, Swift must specify whether an object is empty

Keyword Benefits: Improve code planning and reduce communication costs

Just provide a warning and do not report a compilation error

Nullabel effect: Hint may be empty

Syntax 1

@property (Nonatomic, Strong, Nullabel) NSString * name;

Syntax 2

@property (nonatomic, Strong) NSString * _nullabel name;

Syntax 2

@property (nonatomic, Strong) NSString * __nullabel name;

nonnull function: Hint cannot be empty

Syntax 1

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

Syntax 2

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

Syntax 2

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

null_resettable function: a condition that must be handled as empty get cannot return nil set method can be passed to null

Overriding the Get method

@property (nonatomic, strong,null_resettable) nsstring * name;

You can't use grammar 2 to make an error.

_null_unspecified: Not sure whether it is empty

Rarely used

—————————

!_view change to _view = nil Because Swift does not support the former

Supplement the default between macros (Ns_assume_nonull_begin/end) is nonnull strong

Keyword cannot be used for basic data types

************************************************************************************

2. Generics

Why quit generics? cater to Swift

Generic benefits: 1. Restriction type 2. Improve code specifications reduce communication costs

Generic usage: Type < restriction type >

Generics are just news alerts

Generic benefits are removed from the array to use point syntax

Hints for adding elements to an array

Usage scenarios for generics in development: 1. To restrict collection types

The distinction and use of nullable,nonnull, null_resettable and _null_unspecified

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.