swiftparse-platformpfuser

How to find Name and Lastname in Parse


Using the parse user class I am able to store username, password and email, however I wanted to also store the users name and first name so on parse.com under the core dashboard I added two more columns (firstName and LastName).

 func showName(){
    let user = PFUser()
    let name = user["firstName"]
    let lastname = user["lastName"]
    studentName.text = "\(name) \(lastname) "
}

I want to change the studentName to show the real first and last name of the user. How am I able to get this info from Parse.


Solution

  • This has be adapted from swift 1.2, I haven't tested it out for swift 2 to make sure it fully works, but depending on the version of Xcode, Swift and Parse SDK you are using this should work.

    func showName() {
      if let user = PFUser.currentUser() {
         self.displayName.text = "\(user["firstName"] as! String)  \(user["lastName"] as! String)"
      }
    }