gpt4 book ai didi

swift - 快速在标签中显示数组

转载 作者:搜寻专家 更新时间:2023-11-01 07:02:31 24 4
gpt4 key购买 nike

我想要两个从 Parse 快速获取的显示对象数据。我试过以这种方式使用标签,但它只显示对象中的最后一个元素。请问如何让它显示标签中对象中的所有元素。就像一个元素对应一个标签。谢谢

 let query = PFQuery(className: "Questionnaire")
query.findObjectsInBackground { (objects, error) -> Void in
if error == nil {

// There were no errors in the fetch
if let returnedObjects = objects {
// var text = ""
// Objects Array is not nil
// loop through the array to get each object

for object in returnedObjects {
print(object["question"] as! String)
// text.append(object["question"] as! String)
self.Label.text = (object["question"] as! String)


}


}
}
}

最佳答案

你可以像这样在一行中,然后用, 分隔符加入所有问题,你可以将分隔符更改为任何(空,-,...等等)

if let returnedObjects = returnedObjects {
self.Label.text = returnedObjects.map {($0["question"] as? String) ?? nil}.compactMap({$0}).joined(separator: ",")
}

关于swift - 快速在标签中显示数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50286499/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com