NSError, Swift and nullability

I am writing a toolbox in Objective-C that Swift will use at some point, so I use generics and nullability. What should I do in this situation?

- (NSArray<MyObj *> * __nullable)foo:(NSError **)error; 

I am currently receiving a warning: Pointer is missing a nullability type specifier... for both pointers! I'm pretty sure I should NOT do:

 - (NSArray<MyObj *> * __nullable)foo:(NSError * __autoreleasing __nullable * __nullable)error; 

I AM?

+5
objective-c swift error-handling objective-c-nullability
Oct 18 '15 at 13:41
source share
1 answer

Swift Nullability and Objective-C Blog Entry :

The specific type NSError ** so often used to return errors through method parameters that are always considered a null pointer to a null value of NSError .

However, this remark is indicated as an exception to the โ€œAudited Regionsโ€ rules, and it seems to apply only within the audited region:

 NS_ASSUME_NONNULL_BEGIN @interface MyClass : NSObject - (NSArray<MyObj *> * _Nullable)foo:(NSError **)error; @end NS_ASSUME_NONNULL_END 

Within the scope of the test, any simple pointer type will be considered nonnull (with some exceptions, as indicated above for NSError ).

Outside of the scope you are checking, you really need to write explicitly

 - (NSArray<MyObj *> * _Nullable)foo:(NSError * _Nullable * _Nullable)error; 

to avoid warnings about missing nullability type specifiers.

( _Nullable is the new syntax used in Xcode 7 and replaces __nullable .)

+19
Oct 18 '15 at 2:08
source share



All Articles