ios NS_ASSUME_NONNULL_BEGIN 宏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37956272/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NS_ASSUME_NONNULL_BEGIN Macro
提问by DDP
I am following an online tutorial from team tree house and one of the steps is to create an NSManagedObject subclass for my data model.
我正在学习团队树屋的在线教程,其中一个步骤是为我的数据模型创建一个 NSManagedObject 子类。
When I did that the code automatically generated a class and set of macros at the beginning and and the end:
当我这样做时,代码会在开头和结尾自动生成一个类和一组宏:
NS_ASSUME_NONNULL_BEGIN
NS_ASSUME_NONNULL_BEGIN
NS_ASSUME_NONNULL_END
NS_ASSUME_NONNULL_END
I was searching online but I could not find any documentation about what these guys are doing here. By the way they were defined in the header NSObjCRuntime.h
我在网上搜索,但找不到任何关于这些人在这里做什么的文档。顺便说一下,它们是在头文件NSObjCRuntime.h中定义的
Any ideas what purpose they serve?
任何想法他们服务的目的是什么?
回答by DDP
It's a convenience macro to save you typing nonnullin your headers. From the Swiftblog detailing how new safety features have been incorporated back in Objective-C:
这是一个方便的宏,可以节省您在标题中输入nonnull 的情况。来自Swift博客详细介绍了新的安全特性是如何被合并到Objective-C 中的:
To ease adoption of the new annotations, you can mark certain regions of your Objective-C header files as audited for nullability. Within these regions, any simple pointer type will be assumed to be nonnull.
为了简化新注释的采用,您可以将 Objective-C 头文件的某些区域标记为已审核可空性。在这些区域内,任何简单的指针类型都将被假定为非空。
See Nullability and Objective-C - https://developer.apple.com/swift/blog/?id=25
请参阅可空性和 Objective-C - https://developer.apple.com/swift/blog/?id=25