将PFObject数组的值设置为Swift数组

时间:2015-06-12 21:50:23

标签: xcode swift parse-platform

(我是编程新手,对Parse来说是全新的,所以简单的解释当然很受欢迎)

我想这很简单;我卡住了。我在Parse.com中保存了一个PFObject,其中包含一个包含字符串的数组。我试图在我的Swift应用程序中使用Parse数组中的值设置数组。

var query = PFQuery(className:"ParseHat")
query.getObjectInBackgroundWithId("xxxxxxxxxx")
submittedNames = query["theHat"] as [String]
// submittedNames is declared elsewhere in the code. "theHat" is the key where 
the array is stored in the PFobject

我收到了错误' PFQuery'没有名为' subscript'的成员。我尝试过做一些我对代码没有完全理解但又有其他错误的事情,所以我只是张贴这个,因为它似乎最接近于在Parse中检索对象的方法文档。

1 个答案:

答案 0 :(得分:0)

试试这个......

var query = PFQuery(className: "ParseHat")

query.getObjectInBackgroundWithId("XXXXXXXXX") {
    (objects: PFObject?, error: NSError?) -> Void in

    if error == nil {

        //fetching users

        for object in objects{ //looping through returned data

            self.resultsArray.append(object.objectForKey("XXXXXXXX") as! String)

            //adding the string to var resultsArray = [String]()

        }

    } else {
        println("error :(")

    }
}
相关问题