iOS9 新特性关键字(一)
2016-08-08 16:23
375 查看
/*
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_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) 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;
//}
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_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) 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;
//}
相关文章推荐
- iOS9 新特性 常见关键字
- iOS9新特性之关键字
- ios9新特性之关键字
- IOS9新特性之关键字该怎么学
- iOS9新特性之关键字
- iOS9新特性之常见关键字、泛型
- iOS9新特性之常见关键字
- [10秒学会] - iOS9新特性之常见关键字
- iOS9 新特性关键字
- ios9新特性之关键字
- iOS9新特性之常见关键字
- ios开发ios9新特性关键字学习:泛型,逆变,协变,__kindof
- iOS9新增关键字和一些新特性
- iOS9新增关键字和一些新特性的学习
- 第01天实战技术(01):iOS9新特性之常见关键字
- iOS9 新特性 常见关键字
- 探寻C# 4.0新特性之dynamic关键字
- xcode7.0-iOS9新特性之三:界面适配利器:UIStackView
- iOS9的新特性以及适配方案
- 禁用iOS9 App Transport Security(ATS)特性时不起作用