Pointer is missing a nullability type specifier (__nonnull or __nullable)
我们都知道在swift中,可以使用!和?来表示一个对象是optional的还是non-optional,如view?和view!。而在Objective-C中则没有这一区分,view即可表示这个对象是optional,也可表示是non-optioanl。这样就会造成一个问题:在Swift与Objective-C混编时,Swift编译器并不知道一个Objective-C对象到底是optional还是non-optional,因此这种情况下编译器会隐式地将Objective-C的对象当成是non-optional。
为了解决这个问题,苹果在Xcode 6.3引入了一个Objective-C的新特性:nullability annotations。这一新特性的核心是两个新的类型注释:__nullable和__nonnull。从字面上我们可以猜到,__nullable表示对象可以是NULL或nil,而__nonnull表示对象不应该为空。当我们不遵循这一规则时,编译器就会给出警告。
typedef enum : NSUInteger {
LoadTypeNew, ///下拉刷新,加载最新数据的状态
LoadTypeMore, /// 上拉刷新,加载更多数据的状态
LoadTypeSearch /// 控制器搜索数据的状态
} LoadType;
//这个block , 用来解决是不是已经把数据加载完成了(没有更多的数据了)
typedef void(^SuccessWithLastBlock)(_Nonnull id success, BOOL last);
//这个block , 用来解决请求数据出错的情况(包含error 信息 和服务器返回的错误信息,error为空 ,即为服务器错误)
typedef void(^ErrorMsgBlock)( NSError * _Nullable error,id _Nullable msgBody);
@interface QKYBasicDataController : NSObject
@property (nonatomic,strong,nonnull)SuccessWithLastBlock successWithLastBlock; //默认的成功的回调
@property (nonatomic,strong,nonnull)SuccessBlock successBlock; //默认的成功的回调
@property (nonatomic,strong,nonnull)ErrorMsgBlock errorMsgBlock; //默认的失败的回调
// 传入交互的Block块,这个只是提供一般的例子,在具体的DataController中为了增加可读性,需要自定义
-(void)requestDatasWithSusscessBlock: (_Nullable SuccessBlock ) successBlock ErrorMsgBlock:(_Nullable ErrorMsgBlock )errorMsgBlock;
@end
上边的代码是一个基础ViewModel的代码,在使用block的时候只要加上这两个属性 进行说明就不会有警告了
Pointer is missing a nullability type specifier (__nonnull or __nullable)的更多相关文章
- warning:Pointer is missing a nullability type specifier (__nonnull or __nullable)
当我们定义某个属性的时候 如果当前使用的编译器版本比较高(6.3+)的话经常会遇到这样一个警告:warning:Pointer is missing a nullability type speci ...
- 警告: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- ...
- 做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 ...
- declaration specifier, declarator, type specifier
static struct abc * b; static struct abc : declaration specifier * b : declarator struct abc : type ...
- error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
以前一直用的VC6.0,最近换成VS2010了.哎这几天光折腾VS2010了. 曾经我以为程序没啥头绪忒头疼,现在觉得乱七八糟的编译问题才叫一个头裂=口= 原因:VC6.0中,如果没有直接显示指定的返 ...
随机推荐
- 解决:No module named pkg_resources
今天在装bleach的时候,发现bleach依赖的其中的一个库是html5lib,从pypi下载源码包,执行python setup.py install,报错了: 提示我的setuptools版本过 ...
- 设置DataGridView的某个单元格为ComboBox
怎么将DataGridView的 某个单元格设为ComboBox的样式而不是整列都改变样式? 1.最简单的方法:利用DataGridView提供的DataGridViewComboBoxCell. 写 ...
- 爬虫初探(1)之urllib.request
-----------我是小白------------ urllib.request是python3自带的库(python3.x版本特有),我们用它来请求网页,并获取网页源码. # 导入使用库 imp ...
- sqlserver sp模板
某公司内部的sp模板 create procedure [usp_my_procedure_name] as begin set nocount on; declare @trancount int; ...
- 初识Python
Python 简介 Python 是一个高层次的结合了解释性.编译性.互动性和面向对象的脚本语言. Python 的设计具有很强的可读性,相比其他语言经常使用英文关键字,其他语言的一些标点符号,它具有 ...
- 10000 Reasons(Matt Redman)
这是一首很感动的主内歌曲,听了无首次,还是很感动,这里把歌词贴出来,一方面是为了记忆歌词,另一方面是为以后怀念记忆.(20:44:38) Bless the lord,oh my soul oh m ...
- ASP.NET MVC 多语言方案
前言: 好多年没写文章了,工作很忙,天天加班, 每天都相信不用多久,就会升职加薪,当上总经理,出任CEO,迎娶白富美,走上人生巅峰,想想还有点小激动~~~~ 直到后来发生了邮箱事件,我竟然忘了给邮箱密 ...
- 【BOOM】一款有趣的Javascript动画效果
实践出真知,有的时候看到一些有趣的现象就想着用自己所学的知识复现一下. boomJS 缘起 前几天在 github 上看到同事的一个这样的小项目,在 IOS 上实现了这样一个小动画效果,看上去蛮 ...
- Lesson 13 The Greenwood Boys
Text The Greenwood Boys are group of pop singers. At present, they are visiting all parts of the cou ...
- Key/Value之王Memcached初探:三、Memcached解决Session的分布式存储场景的应用
一.高可用的Session服务器场景简介 1.1 应用服务器的无状态特性 应用层服务器(这里一般指Web服务器)处理网站应用的业务逻辑,应用的一个最显著的特点是:应用的无状态性. PS:提到无状态特性 ...