//
// 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.
}
}
swift3.0 类似 oc 中 obj = nil 的判断
最新推荐文章于 2022-06-24 09:46:08 发布
本文介绍了一个使用Swift实现的ViewController类,该类演示了如何处理nil值,并展示了触摸开始时视图背景颜色的变化及nil值检查的方法。
3641

被折叠的 条评论
为什么被折叠?



