Question

I have a switch on my ViewController, and whenever I press the save button, I want to use NSLog to print out if the switch is On/Off.

My question is, What data type saves the state of a switch? And how would I print out that variable with the state?

EDIT:

If it was a DatePicker, it would be

@property (nonatomic, strong) NSDate *pickerDate; 

I need the Switch version of this. NSSwitch doesn't seem to work.

Was it helpful?

Solution

UISwitch has a BOOL property called "on". Say your switch is called "theSwitch"

if(theSwitch.on) {
   NSLog(@"on")
}
else {

   NSLog(@"off")
}

OTHER TIPS

@property (nonatomic, strong) UISwitch *aSwitch; 


if(aSwitch == nil)
    NSLog("Oops, switch is nil, you cannot save its state");

NSLog(@"switch is:%@", aSwitch.on? @"on", @"off");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top