简体   繁体   English

保存到现有的Parse.com对象

[英]Saving to existing Parse.com object

I am receiving the following errors [1]"Cannot subscript a value of type '[AnyObject]' with an index of type 'String'. [2]Cannot invoke 'saveInBackgroundWithBlock' with an argument list of type '((Bool, NSError?) -> Void)'. I am attempting to save an integer to an existing parse.com column. 我收到以下错误[1]“无法用索引类型'String'下标'[AnyObject]'的值。[2]无法调用类型为'((Bool,NSError的参数列表)'saveInBackgroundWithBlock' ?)-> Void)'。我正在尝试将整数保存到现有的parse.com列中。

func heatUp(){
    let findDataParse = PFQuery(className:"flyerDataFetch")
    findDataParse.whereKey("objectId", equalTo: objectID)
    findDataParse.findObjectsInBackgroundWithBlock{
        (ObjectHolder: [AnyObject]?, error: NSError?) -> Void in
        if (error == nil) {
                //[1] First error
                 if let ObjectHolder = ObjectHolder {
                    ObjectHolder["attention"] = self.count
                }
                //[2] Second error
                ObjectHolder.saveInBackgroundWithBlock {
                    (success: Bool, error: NSError?) -> Void in
                    if (success){
                        println("successful save")
                    }
                  }
                 }
                }

} }

放置PFObject而不是任何对象(将其转换),并为错误而将其擦除或不将其作为可选对象

Change 更改

(ObjectHolder: [AnyObject]?, error: NSError?) -> Void in

To

(ObjectHolder: [String]?, error: NSError?) -> Void in

I'm not 100% sure what this code is supposed to do, but... 我不是100%知道此代码应该做什么,但是...

Error 1: ObjectHolder is an array of AnyObject types. 错误1:ObjectHolder是AnyObject类型的数组。 You're trying to get the "attention" index of ObjectHolder which isn't possible. 您正在尝试获取不可能的ObjectHolder的“注意”索引。 Remember, only numeric values go into the [] of an array for indexing. 请记住,只有数值进入数组的[]才能建立索引。 For example, if you want to get the first value in the array: 例如,如果要获取数组中的第一个值:

value = array[0]

You probably want to get the first PFObject in ObjectHolder using ObjectHolder[0] and THEN do the editing of that column. 您可能想使用ObjectHolder [0]获取ObjectHolder中的第一个PFObject,然后编辑该列。

object = ObjectHolder[0]
object["attention"] = self.count

Error 2: Again, you're trying to do an array of operations on a list of objects. 错误2:同样,您尝试对对象列表进行一系列操作。 Using the object you just created above, do: 使用刚刚在上面创建的对象,执行以下操作:

object.saveInBackgroundWithBlock {...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM