iOS9 新特性关键字(一)

/*

 nullable作用:表示可以为空

 nullable书写规范:

 // 方式一:

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

 // 方式二:

 @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_BEGINNS_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) NSString *name;

 */



/*

    _Null_unspecified:不确定是否为空

    书写方式只有这种

    方式一

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

    方式二

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

 */





@end


@implementation ViewController


//- (void)setName:(NSString *)name

//{

//    if (name == nil) {

//        name = @"123";

//    }

//    _name = name;

//}

//- (NSString *)name

//{

//    if (_name == nil) {

//        _name = @"123";

//    }

//    return _name;

//}


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

// 好处:

// 1.迎合swift

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


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

//- (UIView *)view

//{

//    if (_view == nil) {

//        [self loadView];

//        [self viewDidLoad];

//    }

//    

//    return _view;

//}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值