从Parse类中拉出列并将它们放入数组中

时间:2016-01-27 22:20:29

标签: ios swift parse-platform

好吧,所以我要做的就是从我的班级中取出每一行并将其放入2个阵列,名称和价格。我已经将objectIDs放入一个名为" ids"的数组中。我试着让它打印我填充的2个数组的计数,但它总是回零,这就是我知道它不能正常工作。我按照建议用for循环更新了代码,现在我得到一个"数组超出范围"错误。

    var names: [String] = []
    var prices: [String] = []
    var ids: [String] = [] //a previous part of the code fill this with ids
    var counta = 0 //a previous part of the code fills this with the count of the ids
    var i = 0
    var Deals = PFObject(className:"Deals")

var query = PFQuery(className: "Deals")

    query.whereKey("objectId", equalTo: ids[i] as String)   //pulling the whole row based on objectID
        query.findObjectsInBackgroundWithBlock {
            (objects: [PFObject]?, error: NSError?) -> Void in
            if error == nil{

                for i in 0..<self.counta {

                    self.names.append(self.Deals["Name"] as! String)      //puts name into name array
                    self.prices.append(self.Deals["Price"] as! String)    //puts prices into name array
                }


            }

            else{
                print("Error: \(error!) \(error!.userInfo)")
            }
        }

0 个答案:

没有答案