本文介绍了NSError,Swift和可空性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我在Objective-C中编写一些工具,将在某些时候使用Swift,因此我使用泛型和可空性。在这种情况下我应该做什么? - (NSArray< MyObj *> * __nullable)foo:(NSError * *)错误; 目前我正在收到警告: 指针缺少一个可空性类型说明符... 两个指针!我几乎肯定我不应该这样做: - (NSArray< MyObj *> * __nullable) foo:(NSError * __autoreleasing __nullable * __nullable)错误; 我是吗?解决方案 Swift博客条目可空性和目标C 状态:However, this remark is listed as an exception to the rulesof "Audited Regions", and it seems that it applies only withinan audited region:NS_ASSUME_NONNULL_BEGIN@interface MyClass : NSObject- (NSArray<MyObj *> * _Nullable)foo:(NSError **)error;@endNS_ASSUME_NONNULL_ENDWithin 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<MyObj *> * _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.) 这篇关于NSError,Swift和可空性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-09 09:11