Hi Devin!
Well, I haven't worked with UISwitch at all so I don't know exactly how it works, but I think it shouldn't be a problem... You should have a listener to detect when the user changes a UISwitch's state, and a UISwitch have a property called "on" which is a boolean that simply determines if the switch is turned on or not. If the listener exists you simply should save this property's state in a variable so you can store it and save it in your NSUserDefaults (in fact I think you may save the property itself so you don't even need to store it in a variable). What happens if you don't have a listener (as I've said I don't know because I've never worked with UISwitches)? Well, you should then be aware on when the user can change the switch state... Let me explain with some pseudo-code examples:
If the UISwitch have it's own listener:
Code:
-(void)switchHaveChangedItsState:(UISwitch*)switch // of course if the method exists it will not be called like this ;)
{
self.myBool = switch.on;
}
What if the UISwitch doesn't have a listener (the following it's just an idea, but sure it can be solved in many ways)?
Code:
// In your touch method:
-(void)touchesBegan(...)
{
self.switchState = self.mySwitch.on; // save your switch's state...
}
-(void)touchesEnded(...)
{
if( self.switchState != self.mySwitch.on )
{
// If yes means that since the user touched the screen the switch's value have changed, so it means that the user changed it!
// Here you can save it to NSUserDefaults...
// To save it you simply should copy your NSUserDefault's code here (I've never used NSUserDefaults, I use to save my data in an own-made plist file)
}
}
Well I think it is more or less what you're looking for (or what I've understood, but here are 9.00 am so I'm not even awaken ^_^), if you have any other doubt or this isn't exactly what are you looking for ask me and if I can I will help you!
Regards!