Created
June 16, 2015 02:42
-
-
Save codebeaulieu/9cc7c3df04e87ed6216a to your computer and use it in GitHub Desktop.
switchcell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol SwitchCellDelegate { | |
func didChangeSwitchState(sender sender: SwitchCell, isOn: Bool) | |
} | |
class SwitchCell: UITableViewCell { | |
var cellDelegate: SwitchCellDelegate? | |
@IBOutlet weak var switchLabel: UILabel! | |
@IBOutlet weak var switchState: UISwitch! | |
@IBAction func handleSwitchChange(sender: UISwitch) { | |
if let key = self.switchLabel.text { | |
self.cellDelegate?.didChangeSwitchState(sender: self, isOn: switchState.on) | |
AppDelegate().userDefaults.setValue(switchState.on, forKey: key) | |
AppDelegate().userDefaults.synchronize() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment