• 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

  • 相关阅读:
    CocoaPods 的简单快速安装方法
    macOS Catalina new Shell,解决 The default interactive shell is now zsh
    Mac入门--通过homebrew下载过慢问题
    Mac下安装Android Studio
    Mac更新catalina之后有道词典闪退的解决办法
    mac系统下安装Java开发环境(一)——JDK安装
    聊天案例
    ios中常用k线
    ubuntu连接蓝牙鼠标
    image_transport
  • 原文地址:https://www.cnblogs.com/culing/p/5714372.html
Copyright © 2020-2023  润新知