目标C中什么是非空的? [英] What is nonnull in objective C?
本文介绍了目标C中什么是非空的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人能详细解释为什么在iOS 9中引入了 nonnull
?
Can someone elaborate why is nonnull
introduced in iOS 9 ?
例如, NSArray
方法 +(instancetype)数组;
现在是 +(instancetype nonnull)数组;
这是一个客观的c级功能,它会如何影响现有的应用程序?
Is this an objective-c level feature, and how would this affect the existing apps ?
推荐答案
他们做了确保在类型不可为空的任何地方,它现在是非空
类型。
They have made sure that wherever the type is not-nullable it is now a nonnull
type.
像之前的 NSMutableArray addObject
方法
- (void)addObject:(ObjectType)anObject
现在它已更改为
- (void)addObject:(ObjectType nonnull)anObject
因此,这意味着您无法将null对象( nil
)传递给此方法。同样,在你的情况下
So it means you cannot pass a null object (nil
) to this method. Same way, in your case
+ (instancetype nonnull) array
方法永远不会返回 nil
。
参考: https://developer.apple.com/swift/blog/?id=25
这篇关于目标C中什么是非空的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文