将Parse数据检索到数组时出错

时间:2015-05-30 15:40:27

标签: arrays swift parse-platform

var titles = [String]()
var descriptions = [String]()

 func retrieveData () {

        var query = PFQuery(className: "Main")

        // get the actual data
        query.getFirstObjectInBackgroundWithBlock {
            (object: PFObject?, error: NSError?) -> Void in

            if error != nil || object == nil {

                println("Error retrieving data")

            } else {

                self.titles.append(object["Labels"] as! String) // ERROR!
                self.descriptions.append(object["desc1"] as! String) // ERROR!

            }

        }
    }

我有2个数组,我想从Parse中检索数据并将其添加到这些数组中,但是我收到了这个错误:

 Cannot invoke 'append' with an argument list of type '(String)'

我做错了什么?

编辑:这是我println(object)时的结果:

Optional(<Main: 0x7fc24b84e410, objectId: jy7LrEOMk0, localId: (null)> {
    Labels = labels;   
    desc1 = desc1;
    desc2 = desc2;
    desc3 = desc3;
    desc4 = desc4;
    desc5 = desc5;
})
Message from debugger: got unexpected response to k packet: OK

1 个答案:

答案 0 :(得分:0)

花了几个小时尝试&amp;搜索,这是正确的答案:

self.titles.append(object?.objectForKey("Labels") as! String)
self.descriptions.append(object?.objectForKey("desc1") as! String)

答案很简单,但Parse.com文档不知何故只有一个样本。无论如何,我希望能帮助其他可能遇到同样问题的人。