我不確定爲什麼我的標籤不會更改爲問題字符串。如何在Swift中調用函數?
func GenerateQuestion(){
let FirstNo = Int(arc4random_uniform(10))+1 // first number in sum
let SecondNo = Int(arc4random_uniform(10))+1 // second number in sum
let SymbolNo = Int(arc4random_uniform(4))+1 // number which decides the operator in sum
var OperatorSymbol = ""
var Question = "" // the question
var Answer = Int() // holds answer of the sum
var ButtonNo = Int(arc4random_uniform(4))+1 // number which chooses button to hold correct answer
switch SymbolNo{
case 1 : OperatorSymbol = "+";
Question = "\(FirstNo) + \(SecondNo) = ?";
self.Lbl.text = Question
case 2 : OperatorSymbol = "-";
Question = "\(FirstNo) - \(SecondNo) = ?";
self.Lbl.text = Question
case 3 : OperatorSymbol = "/";
Question = "\(FirstNo)/\(SecondNo) = ?";
self.Lbl.text = Question
case 4 : OperatorSymbol = "x";
Question = "\(FirstNo) x \(SecondNo) = ?;";
self.Lbl.text = Question
default : Question = ""
}
我沒有叫func generateQuestion
,因爲我不知道怎麼樣。我該怎麼辦?
正如官方設計指南所述,通常建議在Swift中使用駝峯函數名稱:http://swift.org/documentation/api-design-guidelines – the4kman
您聲明 - *「我不確定爲什麼我的標籤不會改變「*。然後你聲明 - *「我還沒有調用'func generateQuestion'」*。你只是回答你自己的問題。 – rmaddy
*「我該怎麼辦?」 - 閱讀[Swift編程語言](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/)書。 – rmaddy