Reputation: 313
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")
}
}
}
}
}
Upvotes: 0
Views: 105
Reputation: 1605
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 {...
Upvotes: 0
Reputation: 1252
Put PFObject instead of anyobject (convert it) and for error erase it or dont put it as optional
Upvotes: 1
Reputation: 2918
Change
(ObjectHolder: [AnyObject]?, error: NSError?) -> Void in
To
(ObjectHolder: [String]?, error: NSError?) -> Void in
Upvotes: 0