我们都知道在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. Android Intent Flags

    Intent,顾名思义,即意图,通常用它来启动一个应用程序组件( Activity, Service, 或者 BroadCast Receiver ).在启动一个新的 Activity 时,可以通过给 ...

  2. CentOS7 编译安装 Nodejs (实测 笔记 Centos 7.0 + node 0.10.33)

    环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7.0-1406-x86_64-DVD.iso 安装步骤: 1.准备 1.1 显示系统版 ...

  3. QQ表情的发送与接收

    我想大家对QQ表情一定不会陌生,一个个小头像极大丰富了聊天的乐趣,使得聊天不再是简单的文字叙述,还能够配上喜.怒.哀.乐等表达人物心情的小图片.本文重点要介绍的内容就是如何在微信公众平台使用QQ表情, ...

  4. JQuery之$.ajaxPOST数据

    function postSimpleData() { $.ajax({ type: "POST", url: "/Service/SimpleData", c ...

  5. sql字符串分组

    create function f_myWord(@s varchar(50)) returns varchar(50) as begin declare @i int set @i=1 while ...

  6. 使用java反射机制编写Student类并保存

    定义Student类 package org; public class Student { private String _name = null; ; ; public Student() { } ...

  7. 最近碰到的一些 SSL 问题记录

    最近碰到一些 SSL 的小问题,特记录下. 我们有个 Java 实现的 SSL TCP 服务端,为客户端(PC.Android 和 iOS)提供 SSL 接入连接服务.最近有用户反馈其手机上 App ...

  8. [译] 给PHP开发者的PHP源码-第一部分-源码结构

    文章来自:http://www.hoohack.me/2016/02/04/phps-source-code-for-php-developers-ch 原文:http://blog.ircmaxel ...

  9. 京东招聘Java开发人员

    软件开发工程师(JAVA) 岗位职责: 1. 负责京东核心业务系统的需求分析.设计.开发工作 2. 负责相关技术文档编写工作 3. 解决系统中的关键问题和技术难题 任职要求: 1. 踏实诚恳.责任心强 ...

  10. Module-Zero之启动模板

    返回<Module Zero学习目录> 概览介绍 社交登录 基于Token的认证 单元测试 概览介绍 使用ABP和Module-Zero开始一个新的项目最简单的方式通过ABP官网的模板页面 ...