如何在swift中使用函数输入连接变量名
我想知道如何根据函数输入更改变量名?这样做如何在swift中使用函数输入连接变量名,swift,Swift,我想知道如何根据函数输入更改变量名?这样做 @IBAction func buttonPressed(_ sender: UIButton) { if sender.tag == 1{ updateUI(storyNumber: 3) }else if sender.tag == 2 { updateUI(storyNumber: 2) } } func updateUI(storyNumber: Int ){ storyTe
@IBAction func buttonPressed(_ sender: UIButton) {
if sender.tag == 1{
updateUI(storyNumber: 3)
}else if sender.tag == 2 {
updateUI(storyNumber: 2)
}
}
func updateUI(storyNumber: Int ){
storyTextView.text = story + (storyNumber)
topButton.setTitle(answer +(storeyNumber)+ a, for: .normal)
bottomButton.setTitle(answer +(storeyNumber)+ b, for: .normal)
}
如果a和b不是字符串,那么
func updateUI(storyNumber: Int ){
storyTextView.text = story + "\(storyNumber)"
topButton.setTitle(answer + "\(storyNumber)" + a, for: .normal)
bottomButton.setTitle(answer + "\(storyNumber)" + b, for: .normal)
}
func updateUI(storyNumber: Int ){
storyTextView.text = story + "\(storyNumber)"
topButton.setTitle(answer + " \(storyNumber) " + "\(a)", for: .normal)
bottomButton.setTitle(answer + " \(storyNumber) " + "\(b)", for: .normal)
}
Also you can add spaced too...