swift3.0 类似 oc 中 obj = nil 的判断
发布时间:2020-12-14 06:23:01 所属栏目:百科 来源:网络整理
导读://// ViewController.swift// test_nil_swift//// Created by jeffasd on 17/3/13.// Copyright ? 2017年 jeffasd. All rights reserved.//import UIKitclass ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do
// // ViewController.swift // test_nil_swift // // Created by jeffasd on 17/3/13. // Copyright ? 2017年 jeffasd. All rights reserved. // import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view,typically from a nib. } override func touchesBegan(_ touches: Set<UITouch>,with event: UIEvent?) { showName(nil); self.view.backgroundColor = UIColor.blue; } //MARK: swift3.0判断变量是否存在 func showName(_ name: String?){ if name != nil { print("name") }else{ print("anme is nil") } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |