【发布时间】:2021-04-28 17:16:12
【问题描述】:
我是 Parse 和 Swift 的新手,我正在处理这个项目,我正在尝试创建一个搜索栏,显示我的 Parse 数据库中关键“名称”中的所有项目。
我创建了这个函数,它应该获取所有名称并将它们返回到一个字符串数组中。但相反,数组永远不会被填充,我得到的只是 []。
class Offices {
var name: String
var phone: String
var location: String
init(name: String = "def_name", phone: String = "def_phone", location: String = "def_location") {
self.name = name
self.phone = phone
self.location = location
}
func retrieveName() -> [String] {
var models = [String]()
let queries = PFQuery(className: "Directory")
queries.findObjectsInBackground { (object, error) in
if let error = error {
// The query failed
print(error.localizedDescription)
} else if let object = object {
// The query succeeded with a matching result
for i in object{
models.append(i["name"] as? String ?? self.name)
}
} else {
// The query succeeded but no matching result was found
}
}
return models
}
【问题讨论】:
标签: ios swift xcode parse-platform