warning:Pointer is missing a nullability type specifier (__nonnull or __nullable)
当我们定义某个属性的时候 如果当前使用的编译器版本比较高(6.3+)的话经常会遇到这样一个警告:warning:Pointer is missing a nullability type specifier (__nonnull or __nullable)
苹果在Xcode 6.3引入了一个Objective-C的新特性:nullability annotations。这一新特性的核心是两个新的类型注释:__nullable和__nonnull。从字面上我们可以猜到,__nullable表示对象可以是NULL或nil,而__nonnull表示对象不应该为空。当我们不遵循这一规则时,编译器就会给出警告。
如果需要每个属性或每个方法都去指定nonnull和nullable,是一件非常繁琐的事。苹果为了减轻我们的工作量,专门提供了两个宏:NS_ASSUME_NONNULL_BEGIN和NS_ASSUME_NONNULL_END。在这两个宏之间的代码,所有简单指针对象都被假定为nonnull,因此我们只需要去指定那些nullable的指针。如下代码所示:

不过,为了安全起见,苹果还制定了几条规则:
typedef定义的类型的nullability特性通常依赖于上下文,即使是在Audited Regions中,也不能假定它为nonnull。
复杂的指针类型(如id *)必须显示去指定是nonnull还是nullable。例如,指定一个指向nullable对象的nonnull指针,可以使用”__nullable id * __nonnull”。
我们经常使用的NSError **通常是被假定为一个指向nullable NSError对象的nullable指针。
兼容性
因为Nullability Annotations是Xcode 6.3新加入的,所以我们需要考虑之前的老代码。实际上,苹果已以帮我们处理好了这种兼容问题,我们可以安全地使用它们:
老代码仍然能正常工作, 即使对nonnull对象使用了nil也没有问题。
老代码在需要和swift混编时,在新的swift编译器下会给出一个警告。
nonnull不会影响性能。事实上,我们仍然可以在运行时去判断我们的对象是否为nil。
warning:Pointer is missing a nullability type specifier (__nonnull or __nullable)的更多相关文章
- Pointer is missing a nullability type specifier (__nonnull or __nullable)
我们都知道在swift中,可以使用!和?来表示一个对象是optional的还是non-optional,如view?和view!.而在Objective-C中则没有这一区分,view即可表示这个对象是 ...
- 警告:Pointer is missing a nullability type specifier (__nonnull or __nullable)
当我们定义某个属性的时候 如果当前使用的编译器版本比较高(6.3+)的话经常会遇到这样一个警告: 而且奇怪的是在某些文件中定义这个属性是没有任何警告的 但是在某些文件中定义同样的属性就会报错: 其实 ...
- error C4430:missing type specifier 解决错误
错误 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ...
- MFC中使用ATL报错:error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
我在MFC中使用ATL函数A2W的时候报如下的错误: error C4430: missing type specifier - int assumed. Note: C++ does not sup ...
- error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 解决方法
在VS2012中生成时出错:error C4430: missing type specifier - int assumed. Note: C++ does not support default- ...
- insserv: warning: script 'busybox-httpd' missing LSB tags and overrides
/********************************************************************************* * insserv: warnin ...
- 做MFC的时候引用了头文件但VC还是报missing storage-class or type specifiers
我在客户端clg.h头文件中引用了头文件“ClientSocket.h”,然后在客户端clg.h中的类中声明了类CClientSocket的对象,可是编译报错:d:\vc++\客户端\客户端dlg.h ...
- GetDocument missing storage-class or type specifiers的解决方法
error C2143: syntax error : missing ';' before '*'error C2501: 'CTest1Doc' : missing storage-class o ...
- Ubuntu做Tomcat服务:insserv: warning: script 'tomcat' missing LSB tags and overrides
https://blog.csdn.net/hanchao5272/article/details/79819460 转载自:https://blog.bbzhh.com/index.php/arch ...
随机推荐
- plotly线上绘图和离线绘图的区别
1.线上绘图 import plotly import plotly.plotly as py import plotly.graph_objs as go plotly.tools.set_cred ...
- Jmeter-ServerAgent
You can specify the listening ports as arguments (0 disables listening), default is 4444: $ ./star ...
- Educational Codeforces Round 77 (Rated for Div. 2)D(二分+贪心)
这题二分下界是0,所以二分写法和以往略有不同,注意考虑所有区间,并且不要死循环... #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> ...
- Java方法升级
1. 方法格式 package cn.itcast.day04.demo02; /* 方法其实就是若干语句的功能集合. 方法好比是一个工厂. 蒙牛工厂 原料:奶牛.饲料.水 产出物:奶制品 钢铁工厂 ...
- JS的起源和发展
JS概述 JS主要由三部分组成 ECMAScript BOM DOM 对于ECMAScript的理解 这是JS这个大厦的地基和骨架,是核心的部分 BOM:提供与浏览器进行交互的方法和接口 DOM;提供 ...
- P1567
最大子数组和问题,dp或者分治.. #include <bits/stdc++.h> #define rep(i, a, b) for(int i = a; i <= b; i++) ...
- C语言:计算并输出给定10个数的方差。
//计算并输出给定10个数的方差. #include<math.h> #include<stdio.h> ]) { double p = 0.0,f=0.0,g=0.0; ; ...
- 「CF815C」Karen and Supermarket
传送门 Luogu 解题思路 树形背包. 设 \(f[i][j][0/1]\) 表示在以 \(i\) 为根的子树中选 \(j\) 件商品的最少花费. 边界条件: \(f[i][j][0] = \min ...
- Wireshark 查看指定进程的网络包
Wireshark 查看指定进程的网络包 打开任务管理器,右键筛选列,选中PID(进程标识符): 找到该进程对应的PID,如1200: 在cmd中执行netstat -ano|findstr 1200 ...
- 洛谷P1908 逆序对(线段树解法)
题目描述 猫猫TOM和小老鼠JERRY最近又较量上了,但是毕竟都是成年人,他们已经不喜欢再玩那种你追我赶的游戏,现在他们喜欢玩统计.最近,TOM老猫查阅到一个人类称之为“逆序对”的东西,这东西是这样定 ...