使用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!