我们可以在Objective-C中创建nullable/nonnull属性吗? [英] Can we create nullable/nonnull property in objective-c?

查看:71
本文介绍了我们可以在Objective-C中创建nullable/nonnull属性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果可以的话,我们可以在Objective-C中创建可为空/不为空的属性吗?

Can we create nullable/nonnull property in objective-c if yes then how?

推荐答案

您可以使用_Nullable_Nonnull限定词

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

nonnull:指示指针应该/永远不会为nil.用nonnull注释的指针作为其非可选基值(即NSData)导入到Swift中.

nonnull: Indicates that the pointer should/will never be nil. Pointers annotated with nonnull are imported into Swift as their non-optional base value (i.e., NSData).

nullable:表示通常情况下指针可以为nil.作为可选值(NSURL?)导入到Swift中.

nullable: Indicates that the pointer can be nil in general practice. Imported into Swift as an optional value (NSURL?).

这篇关于我们可以在Objective-C中创建nullable/nonnull属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆