在viewcontroller.swift中 编写如下测试代码
import UIKit
class ViewController: UIViewController {
required init(coder aDecoder: NSCoder) {
print("init");
}
var t : Int;
enum buttonColor:Int
{
case red = 1
case black = 2
case green = 3
case blue = 4
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func color_select_ (color:Int) -> buttonColor
{
var color_ : buttonColor;
switch (color)
{
case 1: print("black");
color_ = .black
case 2: print("blue");
color_ = .green
case 3: print("green");
color_ = .blue
default:
print("red");
}
return color_;
}
var c : buttonColor = color_select_(t); //此处编译工具提示错误。
}
错误提示是:Instance member 't' cannot be used on type 'ViewController‘
麻烦各位老师给一个原因。谢谢。