iosherokuparse-serverpfuser

How to create multiple PFUsers on Parse-Server?


I am using the PFUser class to handle users (on Heroku/mLab) in an iOS app, using a subclass of PFSignUpViewController to create news users, one at a time.

It works fine but here is my problem: sometime I want to create multiple users in one go. Say around 50 users in one time. Obviously I do not want to type them in one by one; I have them ready in a list:

email-01, username-01
email-02, username-02
email-03, username-03
.. etc ..

How can I do that? Is it possible within the iOS app, by some function call? Or do I need to use some external tool?

Michel


Solution

  • I've created a sample project for you, you can sign them up by just using a for loop.

    And of course, you can set up all your users in a JSON file, then use JSONSerialization to get the JSON contents.

    Here is the sample project:

    let userArray = [
        ["username":"user1","email":"abc@a.com","password":"1234"],
        ["username":"user2","email":"abc@b.com","password":"1234"],
        ["username":"user3","email":"abc@c.com","password":"1234"],
        ["username":"user4","email":"abc@d.com","password":"1234"],
        ["username":"user5","email":"abc@e.com","password":"1234"]
    ]
    
    @IBAction func signUp(_ sender: UIButton) {
        var index = 0
        for _ in userArray {
            let user = PFUser()
            user.username = userArray[index]["username"]
            user.password = userArray[index]["password"]
            user.email    = userArray[index]["email"]
            user.signUpInBackground()
    
            index += 1
        }
    }
    

    and there you go, all five users are signed up. enter image description here