4

How to associate nullability keywords with multi-level pointer types in following declaration for (NSError **)error?

- (void)loadSessionForUserId:(nonnull NSString *)userId error:(NSError **)error { ... }

I want to make error nullable and get rid of “Pointer is missing a nullability type specifier (__nonnull or __nullable)”

Error variant with Xcode11: nullability keyword 'nullable' cannot be applied to multi-level pointer type 'NSError *__autoreleasing _Nullable *'

enter image description here

lal
  • 7,410
  • 7
  • 34
  • 45
  • Related: https://stackoverflow.com/questions/37618830/objective-c-nullability-for-output-parameters – rmaddy Oct 13 '17 at 20:53

1 Answers1

2

If you are getting a warning, or error if treat-warning-as-error is on for project, on Xcode 9. Use this format for multi-level pointers:

Solution:

error:(NSError *_Nullable* _Nullable)error

Other error variations:

a) With error:(NSError ** _Nonnull)error Results in compile time error Nullability keyword 'nullable' cannot be applied to multi-level pointer type 'NSError *__autoreleasing *’

b) with error:(NSError * _Nonnull *)error Results in compile time error Pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)

c) with error:(NSError ** _Nullable)error Results in compile time error Pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified)

Open Radar for NSError** without a nullability type shows as a warning which can't be suppressed http://www.openradar.me/21766176

Community
  • 1
  • 1
lal
  • 7,410
  • 7
  • 34
  • 45
  • Ah; you're not adding `NS_ASSUME_NONNULL_BEGIN` and `NS_ASSUME_NONNULL_END` around your interface. Typically that is preferred over individually marking every parameter. With it, you'll get the expected `NSError **` behavior without having to mark it. ("assume nonnull" actually assumes null for indirects, because that's almost always correct.) – Rob Napier Oct 13 '17 at 19:40