ios - 检索表中的所有数据? swift ,解析?

标签 ios swift parse-platform backend

我是 Parse 新手。我有联赛类(class),它有名字。我想从表中获取所有名称并在 TableView 中显示它们。

我写了这样的内容:

   let query = PFQuery(className: "Leagues")
    query.findObjectsInBackgroundWithBlock { (objects: [PFObject]?, error: NSError?) in
        if( objects != nil && error == nil) {
            for i in objects! {
                let n = objects[i] as Leagues
            }
        }else if error != nil {
            print("Error is: \(error)")
        }
    }

错误是:

Type PSObject has no subscript members

如何从表中获取所有姓名?

最佳答案

发生这种情况的原因是 for 循环中的“i”实际上是对 PFObject 的引用,而不是 PFObject 数组。 因此,当编译器指出单个 PFObject 没有任何下标成员时,它会为您提供正确的信息。

试试这个:

let query = PFQuery(className: "Leagues")
    query.findObjectsInBackgroundWithBlock { (objects: [PFObject]?, error: NSError?) in
        if( objects != nil && error == nil) {
            for i in objects! {
                let n = i as Leagues // Assuming your PFObject is a list of Leagues 
            }
        }else if error != nil {
            print("Error is: \(error)")
        }
    }

关于ios - 检索表中的所有数据? swift ,解析?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38241486/

相关文章:

ios - 滚动时避免 UITableView 单元格中的数据重复

ios - Swift - 添加到数组后 tableView 不重新加载

java - 无法将数据保存到 Parse.com 云服务

javascript - 解析云代码回调不起作用

javascript - 解析iOS SDK : Understanding Cloud Code

ios - 如何使用 xcode 12.4 创建未签名的 ipa 文件?无法安装 "Runner"?代码 : Code: -402620388

ios - 应用程序进入后台时使计时器无效

ios - 在 iOS 上调用 posix_spawn

ios - 从另一个 View Controller 访问常量

swift - 将 View 添加为 subview 时,ContentInset 未更新