zoukankan      html  css  js  c++  java
  • iOS9新特性之新添加的关键字

    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

  • 相关阅读:
    2/4 关于 Vue.js 中 this.$nextTick 的个人简单解释
    2/3 初次搭建 Vue 项目遇到的问题汇总
    前端中常见的布局
    如何判断一个变量是否为数组(isArray)
    ubuntu下安装截图工具
    正向代理、反向代理
    javascript中的基本数据类型
    css3 中的渐变
    javascript中的toString()
    ubuntu下面安装nodejs
  • 原文地址:https://www.cnblogs.com/culing/p/5714372.html
Copyright © 2011-2022 走看看