0

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.

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")
                    }
                  }
                 }
                }

}

3 Answers 3

1

Put PFObject instead of anyobject (convert it) and for error erase it or dont put it as optional

Sign up to request clarification or add additional context in comments.

2 Comments

(ObjectHolder: PFObject, error: NSError?) -> Void in What exactly do you mean by convert?
you are querying PFObject named flyerDataFetch ... and you want to get result of objects (in this particular example only one object because id is unique) ... u make background thread to query through objects and u get query with results of anyObjects (as we said - u only get one object but that object is stored in array). To read this object u must convert it in PFObject so that parse understands that it is an object from db and that it can read from it. So u unwrap that anyobject as pfobject (if let .. as? PFObject) and when u do that u can read its properties with object["property"] method
0

Change

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

To

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

Comments

0

I'm not 100% sure what this code is supposed to do, but...

Error 1: ObjectHolder is an array of AnyObject types. You're trying to get the "attention" index of ObjectHolder which isn't possible. 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.

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

Error 2: Again, you're trying to do an array of operations on a list of objects. Using the object you just created above, do:

object.saveInBackgroundWithBlock {...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.