What is nonnull in objective C?

后端 未结 4 477
一向
一向 2021-02-05 09:49

Can someone elaborate why is nonnull introduced in iOS 9 ?

For example, the NSArray method + (instancetype)array; is now + (

4条回答
  •  情深已故
    2021-02-05 10:45

    They have made sure that wherever the type is not-nullable it is now a nonnull type.

    Like earlier NSMutableArray addObject method was

    - (void)addObject:(ObjectType)anObject  
    

    and now it has been changed to

    - (void)addObject:(ObjectType nonnull)anObject
    

    So it means you cannot pass a null object (nil) to this method. Same way, in your case

    + (instancetype nonnull) array
    

    method will never return nil.

    Reference: https://developer.apple.com/swift/blog/?id=25

提交回复
热议问题