integrating security for user objects in swift
<p>I am relatively new to iOS software development.
I am trying to add security for user objects in my parse app.
But have no idea on how to add it to the project.</p>

<p>Should it be like this?</p>

<pre><code>func logInViewController() {
    PFUser.logInWithUsernameInBackground("myname", password: "mypass") {
        (user: PFUser?, error: NSError?) -&gt; Void in
        if user != nil {
            // Do stuff after successful login.

            let user = PFUser.logInWithUsername("my_username", password: "my_password")
            user.username = "my_new_username" // attempt to change username
            user.save() // This succeeds, since the user was authenticated on the device.

            // Get the user from a non-authenticated method.
            let query = PFUser.query()
            let userAgain = query!.getObjectWithId(user.objectId!) as! PFUser

            userAgain.username = "another_username"

            // This will crash, sinse the PFUser is not authenticated
            userAgain.save()

        } else {
            // The login failed. Check error to see why.

        }
        let currentUser = PFUser.currentUser()
        if currentUser != nil {
            // Do stuff with the user
        } else {
            // Show the signup or login screen.
        }
    }
}
</code></pre>

<p>or like this?</p>

<pre><code>func userOnlyNameChange() {
    let user = PFUser.logInWithUsername("my_username", password: "my_password")
    user.username = "my_new_username" // attempt to change username
    user.save() // This succeeds, since the user was authenticated on the device.

    // Get the user from a non-authenticated method.
    let query = PFUser.query()
    let userAgain = query!.getObjectWithId(user.objectId!) as! PFUser

    userAgain.username = "another_username"

    // This will crash, sinse the PFUser is not authenticated
    userAgain.save()
}
</code></pre>

<p>or have I just done it completely wrong?</p>