Change your code to the following:
-(BOOL)switched:(UISwitch *)currentSwitch{
return [currentSwitch isOn];
}
Question
I have a function that checks to see if the UISwitch in the parameter is switched on, if it is, then it will return true. I have an if statement that checks if the function returns true, if it is in fact true, it should nslog, but it doesnt. Any ideas on why when I press the switch it doesnt run? Here's what i'm doing:
-(BOOL)switched:(UISwitch *)currentSwitch{
return NO;
if([currentSwitch isOn]){
return YES;
}
}
viewWillDisappear{
if([self switched:campSwitch] == YES){
NSLog(@"THE FUNCTION RETURNED TRUE");
}
}
Solution
Change your code to the following:
-(BOOL)switched:(UISwitch *)currentSwitch{
return [currentSwitch isOn];
}
OTHER TIPS
-(BOOL)switched:(UISwitch *)currentSwitch{
return [currentSwitch isOn];
}
-(void)viewWillDisappear:(BOOL)animated{
if([self switched:mySwitch]){
[self saveToCoreData];
NSLog(@"mySwitch was on.");
}
}