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");
    }
}
Was it helpful?

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.");
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top