简体   繁体   English

我们可以在objective-c中创建可空/非空的属性吗?

[英]Can we create nullable/nonnull property in objective-c?

如果是,那么我们可以在objective-c中创建可空/非空的属性吗?

You can use _Nullable and _Nonnull qualifiers 您可以使用_Nullable_Nonnull限定符

@property (copy, nullable) NSString *name;
@property (copy, nonnull) NSArray *allItems;

nonnull: Indicates that the pointer should/will never be nil. nonnull:表示指针应该/将永远不会为nil。 Pointers annotated with nonnull are imported into Swift as their non-optional base value (ie, NSData). 用nonnull注释的指针作为非可选的基值(即NSData)导入Swift。

nullable: Indicates that the pointer can be nil in general practice. nullable:表示在一般练习中指针可以为nil。 Imported into Swift as an optional value (NSURL?). 导入Swift作为可选值(NSURL?)。

You can use _Nullable and _Nonnull qualifiers as you see fit. 您可以根据需要使用_Nullable_Nonnull限定符。 (Put them in the same place as you'd place a const qualifier). (将它们放在与放置const限定符相同的位置)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM