I\'m writing a set of tools in Objective-C that will be used by Swift at some point so I\'m using generics and nullability. What am I supposed to do in this situation?
The Swift blog entry Nullability and Objective-C states:
The particular type
NSError **
is so often used to return errors via method parameters that it is always assumed to be a nullable pointer to a nullableNSError
reference.
However, this remark is listed as an exception to the rules of "Audited Regions", and it seems that it applies only within an audited region:
NS_ASSUME_NONNULL_BEGIN
@interface MyClass : NSObject
- (NSArray * _Nullable)foo:(NSError **)error;
@end
NS_ASSUME_NONNULL_END
Within an audited region, any simple pointer type will be assumed to be nonnull
(with some exceptions as the above-mentioned for NSError
).
Outside of an audited region, you actually have to write explicitly
- (NSArray * _Nullable)foo:(NSError * _Nullable * _Nullable)error;
to avoid warnings about missing nullability type specifiers.
(_Nullable
is the newer syntax used in Xcode 7 and replaces __nullable
.)