我在一个小的单一窗格应用程序中管理不同的语言,为每个注释使用不同的字符串数组,由整数变量"userLang"索引,然后设置label.text = array [index].基本代码是:
import UIKit
class ViewController: UIViewController {
var userLang = 0
var arrayOne = ["hi", "hola"]
var arrayTwo = ["Bye", "Adios"]
@IBOutlet weak var msgArrayOne: UILabel!
@IBOutlet weak var msgArrayTwo: UILabel!
msgArrayOne.text = arrayOne[userLang] //Error here: !Expected declaration
msgArrayTwo.text = arrayTwo[userLang] //odd, but this line gets no error until I
//remove the first line above, then
//this line gets the same error.
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically …Run Code Online (Sandbox Code Playgroud)