How to use nonnull and nullable Objective-C keywords in block-based API method

后端 未结 6 1376
暗喜
暗喜 2020-12-22 22:13

Consider the following method

- (void)methodWithArg:(NSString *)arg1 andArg:(NSString *)arg2 completionHandler:(void (^)(NSArray *results, NSError *error))co         


        
6条回答
  •  难免孤独
    2020-12-22 22:53

    This seems to be working

    - (void)methodWithArg:(nonnull NSString *)arg1 
      andArg:(nullable NSString *)arg2 completionHandler:(nullable void (^)
      (NSArray * _Nullable results, NSError * _Nonnull error))completionHandler
    

    You need to specify nullability both for the block and its parameters...

    EDIT: For more information, see Swift Blog

提交回复
热议问题