前端之家收集整理的这篇文章主要介绍了
swift3.0 类似 oc 中 obj = nil 的判断,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
//
// 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.
}
}