0
votes

so yeah i'm new to swift, and i'm developing an iOS application for my final project my problem is as follows:

the app ask the user when he/she sign up to specify which gender male/female, the value stored in the User Class in parse under a column named "gender".

in my app, males and females will not have the same menu and interface. based on that, i want to check when the user login wether he/she are a male or a female and then redirect each one to the related interface.

i couldn't figure out the right query for that, any help will be appreciated. thank you

3

3 Answers

0
votes

Try this:

if let user = PFUser.currentUser() {

   let gender = user.objectForKey("gender") as! String
}
0
votes

When the user is signing up the code will go like this

let's you are getting the username password and email from a textfield. Let's say you have UIPicker that shows the gender ["Male","Female"], so create a function that return the value selected.

var genderSelection = // assign the function here ...

let user = PFUser()
user.username = usernameTextLabel.text
user.password = passwordTextLabel.text
user.email = emailTextLabel.text
user["gender"] = genderSelection   //<----
user.signUpInBackgroundWithBlock(succeeded: Bool! , error:NSError!) -> Void in
            if (error == nil)
            {
              // yay success 
            }

So now when you are querying the code will goes like that

let query  = PFQuery(classname: "")
query.whereKey("gender" equalTo:"Male")

or

 query.whereKey("gender" equalTo:"Female")
0
votes

thank you guys, your answers helped me a lot

here is my code after editing if somebody faces the same issue in the future

PFUser.logInWithUsernameInBackground(user, password: pass){ 
            (user:PFUser?, error:NSError?) -> Void in
            if user != nil {

                if let user = PFUser.currentUser() {

                    var gender = user.objectForKey("gender") as! String

                    if gender == "Male" {

                        self.performSegueWithIdentifier("Male", sender: self)
                    }else {

                        self.performSegueWithIdentifier("Female", sender: self)
                    }
                }