What_Ever
What_Ever

Reputation: 3

Parse: How can I update all rows with the same key value

How can I update all rows with the same key value in a Parse class? As my code, I think Parse would cost a lot of my money if there are 100 objects per user. Is there any other way to do that?

    let username = PFUser.currentUser()?.username
    let objectQuery = PFQuery(className: "FriendList")
    objectQuery.whereKey("username", equalTo: username!)

    objectQuery.findObjectsInBackgroundWithBlock { (friendList:[AnyObject]?, error:NSError?) -> Void in
        if let friendList = friendList as? [PFObject] {
            for myInfo in friendList {
                myInfo["contact"] = contact
                myInfo["portrait"] = PFFile(data: portraitNSData)
                myInfo["company"] = company
                myInfo["position"] = position
                myInfo.save()  // create a request?
            }
        }
    }

Upvotes: 0

Views: 319

Answers (3)

picciano
picciano

Reputation: 22701

It would be best to create a CloudCode function. Then call that function from iOS. It's not difficult, see their documentation here: Parse.com

Upvotes: 0

Icaro
Icaro

Reputation: 14845

Parse has a functions to object see to save many objects (see documentation here)

PFObject.saveAllInBackground(array, block: {
        (succeeded: Bool, error: NSError!) -> Void in
        if (error != nil) {
            println("Error saving: \(error)")
        }
    })

Unfortunately the documentation is not update to Swift but you can see a list of the function in objective-c

  • saveAll:

  • saveAll:error:

  • saveAllInBackground:

  • saveAllInBackground:block:

Upvotes: 0

Ivan Nesterenko
Ivan Nesterenko

Reputation: 969

Form array of needed objects and than just

PFObject.saveAllInBackground(objectsArray)

Upvotes: 1

Related Questions