-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!
}
有关最佳实现方法的建议?这是我试图完成的伪代码