我们都知道在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)的更多相关文章

  1. warning:Pointer is missing a nullability type specifier (__nonnull or __nullable)

    当我们定义某个属性的时候  如果当前使用的编译器版本比较高(6.3+)的话经常会遇到这样一个警告:warning:Pointer is missing a nullability type speci ...

  2. 警告:Pointer is missing a nullability type specifier (__nonnull or __nullable)

    当我们定义某个属性的时候  如果当前使用的编译器版本比较高(6.3+)的话经常会遇到这样一个警告: 而且奇怪的是在某些文件中定义这个属性是没有任何警告的 但是在某些文件中定义同样的属性就会报错: 其实 ...

  3. error C4430:missing type specifier 解决错误

    错误    3    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int ...

  4. 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 ...

  5. 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- ...

  6. 做MFC的时候引用了头文件但VC还是报missing storage-class or type specifiers

    我在客户端clg.h头文件中引用了头文件“ClientSocket.h”,然后在客户端clg.h中的类中声明了类CClientSocket的对象,可是编译报错:d:\vc++\客户端\客户端dlg.h ...

  7. GetDocument missing storage-class or type specifiers的解决方法

    error C2143: syntax error : missing ';' before '*'error C2501: 'CTest1Doc' : missing storage-class o ...

  8. declaration specifier, declarator, type specifier

    static struct abc * b; static struct abc : declaration specifier * b : declarator struct abc : type ...

  9. error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    以前一直用的VC6.0,最近换成VS2010了.哎这几天光折腾VS2010了. 曾经我以为程序没啥头绪忒头疼,现在觉得乱七八糟的编译问题才叫一个头裂=口= 原因:VC6.0中,如果没有直接显示指定的返 ...

随机推荐

  1. php安装配置那些事(本文纯属个人记事与技术无关)

    上周由于项目需要,又拿起了三年没动过的php,从安装环境到配置,大体已经忘干净,于是咨询同学问度娘,终于在我的win7系统下安装了xampp的集成环境+NetBeans IDE 8.0,于是导入项目文 ...

  2. highchart 添加新的series

    code: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" c ...

  3. 第一个独立开发的游戏 怪斯特:零 已经上线APP STORE!

    今天是个值得纪念的日子,而且是双喜临门 2年多来的摸爬滚打,终于有了回报 第一喜:自己独立开发的游戏 怪斯特:零 已经通过审核并上架APP STORE! 第二喜:迈入了自己期待2年之久的游戏行业,年后 ...

  4. 图——拓扑排序(uva10305)

    John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...

  5. pythonchallenge 解谜 Level 8

    #-*- coding:utf-8 -*- #代码版本均为python 3.5.1 #Level 7 import bz2 un=b'BZh91AY&SYA\xaf\x82\r\x00\x00 ...

  6. nginx超时重发

    最近一直遇到一个bug: 客户端会二次请求服务端,服务端多次调用remote服务. 特点是,这些请求都是模型切片相关的,耗时很长的请求,往往需要1分钟左右. 开始以为是客户端代码有问题,进行了二次请求 ...

  7. U盘安装Ubuntu 10.4 Server

    试了几次的U盘安装Ubuntu Server失败后,只能求助网络了,找了半天终于安装成功了.问题就是虽然从U盘启动了安装程序,但是在系统安装到一半的过程中,会进行CD-ROM的检查,检查不到安装程序, ...

  8. 使用Gemini构建自己的IDE

    你的项目中的领域特定语言是否需要自己的IDE?Visual Studio Shell是选择之一,但是过于庞大不易部署,而且很难使用.Tim Jones的Gemini框架是一个轻量级替代方案. Gemi ...

  9. 全新 Mac 安装指南(编程篇)(环境变量、Shell 终端、SSH 远程连接)

    注:本文专门用于指导对计算机编程与设计(尤其是互联网产品开发与设计)感兴趣的 Mac 新用户,如何在 Mac OS X 系统上配置开发与上网环境,另有<全新 Mac 安装指南(通用篇)>作 ...

  10. AnguarJS 第一天----Hello World

    AngularJS是什么? AngularJS是目前很火的前端JS框架之一, AngularJS的开发团队将其描述为一种构建动态Web应用的结构化框架.它是完全使用JavaScript编写的客户端技术 ...