-1
我試圖創建一個空的全局字符串arrray斯威夫特全球陣列
struct GlobalVariables {
static var globalString = [String]()
}
我想通過將字符串值放入數組
func percentageCalculation() -> String {
var FinalString = String()
for i in 1...100 {
let tstring = String("\(i)%\n")
GlobalVariables.globalString[i] = tstring
}
return FinalString
}
然後outputing初始化它像這樣全局字符串值到我的tableview。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
let testLabel = cell?.viewWithTag(1) as! UITextView
testLabel.text = GlobalVariables.globalString[indexPath.row]
return cell!
}
有關最佳實現方法的建議?這是我試圖完成的僞代碼