加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – XCode中与null相关的属性属性有什么作用?

发布时间:2020-12-15 01:44:56 所属栏目:百科 来源:网络整理
导读:使用XCode 6.3,我注意到了一些属性属性,即: 非空的 null_resettable 可空的 有人可以解释他们在申请时做了什么吗? 解决方法 Apple添加了两个新类型的注释:__nullable和__nonnull. __nullable指针可能具有NULL或nil值,而__nonnull指针不应具有. 正如您应该
使用XCode 6.3,我注意到了一些属性属性,即:

>非空的
> null_resettable
>可空的

有人可以解释他们在申请时做了什么吗?

解决方法

Apple添加了两个新类型的注释:__nullable和__nonnull.
__nullable指针可能具有NULL或nil值,而__nonnull指针不应具有.

正如您应该在swift中知道的那样,您可以使用选项(?),但在Objective-C中则不能.这些属性允许您创建Objective-C代码,当您违反规则时,swift和编译器会更容易理解这些代码,例如:

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

这将被迅速“翻译”为:

var name: String?
var allItems: [AnyObject]!

这取自NSHipster:

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: Indicates that the pointer can be nil in general practice.
Imported into Swift as an optional value (NSURL?).

null_unspecified: Continues the current functionality of
importing into Swift as an implicitly unwrapped optional,ideally to
be used during this annotation process only.

null_resettable: Indicates that while a property will always have a value,it can be reset by assigning nil. Properties with a non-nil default value can be annotated this way,like tintColor. Imported into Swift as a (relatively safe) implicitly unwrapped optional. Document accordingly!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读