有人可以详细说明为什么吗nonnull
iOS 9 中引入?
例如,NSArray
method + (instancetype)array;
is now + (instancetype nonnull)array;
参考:https://developer.apple.com/library/prerelease/ios/releasenotes/General/iOS90APIDiffs/frameworks/Foundation.html https://developer.apple.com/library/prerelease/ios/releasenotes/General/iOS90APIDiffs/frameworks/Foundation.html
这是 Objective-C 级别的功能吗?这将如何影响现有的应用程序?
他们确保只要类型不可为空,它现在就是一个nonnull
type.
就像之前一样NSMutableArray addObject
方法是
- (void)addObject:(ObjectType)anObject
现在它已更改为
- (void)addObject:(ObjectType nonnull)anObject
所以这意味着你不能传递一个空对象(nil
)到这个方法。同样的方式,在你的情况下
+ (nonnull instancetype) array
方法永远不会返回nil
.
参考:https://developer.apple.com/swift/blog/?id=25 https://developer.apple.com/swift/blog/?id=25
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)