iOS9新特性之關鍵字

來源:互聯網
上載者:User

標籤:

////  ViewController.m//  01-iOS9新特性之常見關鍵字////  Created by kun on 16/8/16.//  Copyright © 2016年 kun. All rights reserved.///* nullable:1,怎麼使用(文法)2,什麼時候使用(作用) nullable作用:可能為空白 關鍵字目的:迎合swift,swift是個強語言,swift必須指定一個對象是否為空白 關鍵字好處:提高代碼規範,減少溝通成本 nullable 文法1 @property (nonatomic, strong, nullable) NSString *name; nullable 文法2 @property (nonatomic, strong) NSString *_Nullable name; nullable 文法3 @property (nonatomic, strong) NSString *__nullable name; *//* nonnull:1,怎麼使用(文法)2,什麼時候使用(作用) nonnull作用:不可為空  nonnull 文法1 @property (nonatomic, strong, nonnull) NSString *name; nonnull 文法2 @property (nonatomic, strong) NSString *_Nonnull name; nonnull 文法3 @property (nonatomic, strong) NSString *__nonnull name;  null_resettable nonnull *//* null_resettable:1,怎麼使用(文法)2,什麼時候使用(作用) null_resettable:必須處理為空白的情況,重寫get方法 null_resettable作用:get方法不可為空, set可以傳入為空白 關鍵字目的:迎合swift,swift是個強語言,swift必須指定一個對象是否為空白 關鍵字好處:提高代碼規範,減少溝通成本    文法1 @property (nonatomic, strong, null_resettable) NSString *name;  *//*    _Null_unspecified:不確定是否為空白 *//* 在下面兩個宏之間的屬性預設為nonnull NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_END */#import "ViewController.h"@interface ViewController ()// nullable// nonnull// null_resettable 處理為空白的情況@property (nonatomic, strong, null_resettable) NSString *name;//@property (nonatomic, strong) NSString *_Nullable name;//@property (nonatomic, strong) NSString *__nullable name;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    }- (NSString *)name{    if ( _name == nil )    {        _name = @"";    }    return _name;}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}@end

 

iOS9新特性之關鍵字

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.