Skip to content

Instantly share code, notes, and snippets.

@codebeaulieu
Created June 16, 2015 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codebeaulieu/9cc7c3df04e87ed6216a to your computer and use it in GitHub Desktop.
Save codebeaulieu/9cc7c3df04e87ed6216a to your computer and use it in GitHub Desktop.
switchcell
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