美文网首页
iOS9新特性之常见关键字

iOS9新特性之常见关键字

作者: 爱哼的阿狸 | 来源:发表于2016-08-17 16:26 被阅读0次

    nullable作用:表示可以为空

    nullable书写规范:

    // 方式一:

    @property (nonatomic, strong, nullable) NSStringname;

    // 方式二:

    @property (nonatomic, strong) NSString_Nullable name;

    // 方式三:

    @property (nonatomic, strong) NSString *__nullable name;

    /

    //@property (nonatomic, strong) NSString__nullable name;

    //@property (nonatomic, strong) NSString * name;

    /*

    nonnull: non:非 null:空

    书写格式:

    @property (nonatomic, strong, nonnull) NSString *icon;

    @property (nonatomic, strong) NSString * _Nonnull icon;

    @property (nonatomic, strong) NSString * __nonnull icon;

    */

    /

    在NS_ASSUME_NONNULL_BEGIN和NS_ASSUME_NONNULL_END之间,定义的所有对象属性和方法默认都是nonnull/

    // 方法中,关键字书写规范

    /**

    (nonnull NSString)test:(nonnull NSString)str;

    (NSString_Nonnull)test1:(NSString_Nonnull)str;

    */

    //@property (nonatomic, assign) int age;

    /

    null_resettable: get:不能返回为空, set可以为空

    // 注意;如果使用null_resettable,必须 重写get方法或者set方法,处理传递的值为空的情况

    // 书写方式:

    @property (nonatomic, strong, null_resettable) NSStringname;

    */

    /

    _Null_unspecified:不确定是否为空

    书写方式只有这种

    方式一

    @property (nonatomic, strong) NSString_Null_unspecified name;

    方式二

    @property (nonatomic, strong) NSString__null_unspecified name;/

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

    // 好处:

    // 1.迎合swift

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

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

    文/我勒个去的(简书作者)

    原文链接:http://www.jianshu.com/p/f284204f9a98

    著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。

    相关文章

      网友评论

          本文标题:iOS9新特性之常见关键字

          本文链接:https://www.haomeiwen.com/subject/ijnslttx.html