Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

What to put for "expression" in a switch statement?

In my app I want to be able to switch back and fourth between male or female buttons.

[Screenshot: https://www.dropbox.com/s/pev3fldj85xstjz/Screenshot%202015-02-19%2014.22.29.png?dl=0]

To do this I assume I have to use a switch statement but don't know what I would use for the expression when I'm switching between two buttons. Any help is great :)

1 Answer

You can just use an if and an else if. If they hit the male button, store male in a variable. If they hit the female button, store female. Are you using Swift or Objective-C? Obj-C can only use numerical values in switch statements. With Swift you can use strings.