Objective-C nullability for output parameters

前端 未结 1 1394
迷失自我
迷失自我 2021-01-18 08:17

I\'m adding nullability specifiers to a class, and I have some pointer-to-pointer output parameters, like (NSString**), because the method returns multiple obje

1条回答
  •  盖世英雄少女心
    2021-01-18 08:48

    You have two pointers so you need two nullability specifiers.

    - (void)someMethod:(NSString * _Nullable * _Nonnull)out
    

    This means you must pass in a non-null pointer but you may get back a null result.

    This will fail:

    [someObject someMethod:nil];
    

    This will work:

    NSString *result = nil;
    [someObject someMethod:&result];
    

    0 讨论(0)
提交回复
热议问题