Я получаю ошибку распаковки при передаче значения другому контроллеру представления и задаю равным выводу? (Swift 3.0)
Я продолжаю получать эту ошибку, когда пытаюсь установить возвращаемые значения моей функции для вывода метки.
import UIKit
class finalData: UIViewController {
var userNum: Int!
var computerNum: Int!
@IBOutlet var output: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
self.output.text = chooseWinner(userNum: userNum, computerNum: computerNum)
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func chooseWinner(userNum : Int, computerNum : Int) -> String {
if userNum == computerNum {
return "There is a tie"
}else if userNum == 1 && computerNum == 2{
return "You lost!"
}else if userNum == 1 && computerNum == 3{
return "You won!"
}else if userNum == 2 && computerNum == 1{
return "You won!"
}
else if userNum == 2 && computerNum == 3{
return "You lost!"
}else if userNum == 3 && computerNum == 1{
return "You lost!"
}
else if userNum == 3 && computerNum == 2{
return "You won!"
}else{
return "value"
}
}
func findPlayerImage (firstImage: Int) -> UIImage{
if userNum == 1{
return #imageLiteral(resourceName: "black")
}else if userNum == 2{
return #imageLiteral(resourceName: "black")
}else{
return #imageLiteral(resourceName: "black")
}
}
func findCompImage (secondImage: Int) -> UIImage{
if computerNum == 1{
return #imageLiteral(resourceName: "black")
}else if computerNum == 2{
return #imageLiteral(resourceName: "black")
}else{
return #imageLiteral(resourceName: "black")
}
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
Я пытаюсь передать числа этому контроллеру представления, а затем вызвать функцию для возврата строки (я делаю камень, ножницы, бумага). Но когда я устанавливаю выход = функцию, это дает мне ошибку развертывания.
1 ответ
Решение
Я убедился, что мои связи были хорошими.
Затем я передал значение в другую раскадровку и установил значение по умолчанию output
в "value"
, Когда я передал строку в вывод, она изменилась.
Спасибо всем выше, а также. ^