// // 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. } }