operation = (sender as AnyObject).tag
我正在使用计算器应用程序,而在底部,我尝试将操作发送到sender.tag,但出现错误
无法分配类型为“ Int!”的值键入“字符串”
This error also generates more errors in the bottom like
“替代”只能在类成员上指定”
“'super'不能在班级成员之外使用”
“'override'只能在类成员上指定”
“'super'不能在班级成员之外使用”
这些行会产生错误吗?
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.
}
答案 0 :(得分:2)
错误非常明显。您的operation
变量是String
。您正在尝试为其分配一个不兼容的类型Int
。
let number = (sender as AnyObject).tag
operation = String(number)
OR
operation = "\(number)"
您的课堂应该看起来像这样。
class YourClass: UIViewController {
// ...
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.
}
}