iOS9 新出的关键字:用来修饰属性,或者方法的参数,返回值

好处:1.迎合swift

2.提高我们开发人员开发规范,减少程序员之间的交流

注意:iOS9新出的的关键字nonnull,nullable,null_unspecified,null_resettable只能修饰对象,不能修饰基本数据类型

nullable : 修饰的对象可以为空

书写方式:

1.@property (nonatomic , strong) NSString * __nullable company;

2.@property (nonatomic , strong , nullable) NSString *company;

3.@property (nonatomic , strong ) NSString *_Nullable company;

nonnull  : 修饰的对象不可以为空

书写方式:

1.@property (nonatomic , strong) NSString * __nonnull company;

2.@property (nonatomic , strong , nonnull) NSString *company;

3.@property (nonatomic , strong ) NSString *_Nonnull company;

null_resettable  : set方法参数可以为空,get方法返回值不能为空,用孩关键字修饰的对象,必须重写set或get方法处理为空情况

书写方式:只有这一种方式

@property (nonatomic , strong , null_resettable) NSString *company;

-(NSString *)company

{

if (_company == nil) {

_company = @"1";

}

return _company;

}

-(void)setCompany:(NSString *)company

{

if (company == nil) {

company = @"1";

}

}

null_unspecified  : 不确定是否为空

书写方式:

1.@property (nonatomic , strong , null_unspecified) NSString *company;

2.@property (nonatomic , strong ) NSString * __null_unspecified company;

@property (nonatomic , strong ) NSString * _Null_unspecified company;

NS_ASSUME_NONNULL_BEGIN  : 宏区间,在这个区域里的对象、方法的参数或返回值都不能为空

NS_ASSUME_NONNULL_END

书写方式:

NS_ASSUME_NONNULL_BEGIN

@property (nonatomic ) NSString *name;

@property (nonatomic , assign ) int age;

-(NSString *)getStr:(NSString *)str;

NS_ASSUME_NONNULL_END

iOS9新特性之新添加的关键字的更多相关文章

  1. JDK1.8之后的新特性和新接口

    接口的旧特性: 就特性下接口中只有: 常量(必须赋值) 抽象方法abstract(和final static private三个关键字冲突) interface Inter { //int a ; / ...

  2. JDK1.8新特性——使用新的方式遍历集合

    JDK1.8新特性——使用新的方式遍历集合 摘要:本文主要学习了在JDK1.8中新增的遍历集合的方式. 遍历List 方法: default void forEach(Consumer<? su ...

  3. Python - 3.8 新特性之仅位置参数 & 仅关键字参数

    前置知识 Python 函数:https://www.cnblogs.com/poloyy/p/15092393.html 什么是仅限位置形参 仅限位置形参是 Python 3.8 才有的新特性 新增 ...

  4. HTML5 的新特性以及新标签的浏览器兼容问题

    新特性: HTML5 现在已经不是 SGML 的子集,主要是关于图像,位置,存储,多任务等功能的增加. 1)  拖拽释放(Drag and drop) API 2)  语义化更好的内容标签(heade ...

  5. Kubernetes1.3新特性:新的资源回收控制器

    (一)  核心概念 在kubernetes1.3中新增了一个资源回收控制器GarbaseCollector,用这个控制器来替代kubernetes1.3中的资源回收控制器GC. 如下为kubernet ...

  6. 再来看看Java的新特性——其他新特性

    关于剩余Java8新特性知识点总结,包含:默认方法.Optional.CompletableFuture.时间相关. 默认方法 默认方法皆在帮助Java新功能可以兼容低版本JDK已开发的程序. 比如说 ...

  7. Firefox 23中的新特性(新陷阱)

    话说有一天突然发现我们的网站页面上的JQuery功能都失效了,Firebug中显示如下的错误 Blocked loading mixed active content "http://xxx ...

  8. java7新特性 java8新特性

    Java 7 的7个新特性 Java7语法新特性 JAVA8 十大新特性详解 http://www.jb51.net/article/48304.htm

  9. hadoop3.0新特性及新功能

    Hadoop-3.0.0-alpha2版本发布,相比之前的hadoop-2.x有一系列的功能增强.但目前还是个alpha版本,有很多bug,且不能保证API的稳定和质量. 主要变化 Java最低版本要 ...

  10. [PHP7.0-PHP7.2]的新特性和新变更

    php7发布已经升级到7.2.里面发生了很多的变化.本文整理php7.0至php7.2的新特性和一些变化. 参考资料: http://php.net/manual/zh/migration70.new ...

随机推荐

  1. 转 Vim操作

    传送门 vim全局替换命令   语法为 :[addr]s/源字符串/目的字符串/[option]全局替换命令为::%s/源字符串/目的字符串/g [addr] 表示检索范围,省略时表示当前行.如:“1 ...

  2. PatentTips - MPLS Network System

    MPLS (Multi Protocol Label Switching) network system has been watched with keen interest as a techni ...

  3. power path 對 UI 上的電池容量曲線 battery curve 百分比 的 改善

    Maintenance.Recharging charger ic 對電池充電時有一種名為 maintenance.recharging 的行為, charger ic 對 電池 充電時,當充滿後,它 ...

  4. hdu 1588(矩阵好题+递归求解等比数列)

    Gauss Fibonacci Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  5. AC日记——dispatching bzoj 2809

    2809: [Apio2012]dispatching Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 3290  Solved: 1740[Submi ...

  6. js-异步请求音频完成后页面显示

    var ajax = new XMLHttpRequest(); ajax.open("get", "http://gzmylike.wedei.com/zt/gzyan ...

  7. Powershell简介及其编程访问

    Powershell是下一代的命令行外壳程序,较之于它的前身(cmd.exe),它的功能更加强大,也更加易用.最根本的区别在于它是基于对象的操作(基于.NET Framework),而不是基于字符串的 ...

  8. gitlab升级、汉化、修改root密码

    1.gitlab升级 # 查看当前版本 head -1 /opt/gitlab/version-manifest.txt gitlab-ce 8.9.5 grep "^external_ur ...

  9. HDU 1045 Fire Net 状压暴力

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others)  ...

  10. PyTorch学习问题记录

    Q1:def train() 中的model.train()的作用是什么?为什么要写? A1:class torch.nn.Module中 train(mode=True) Sets the modu ...