Skip to content

Instantly share code, notes, and snippets.

@wethu
Created February 1, 2015 05:02
Show Gist options
  • Select an option

  • Save wethu/e082a9723cff63fc7781 to your computer and use it in GitHub Desktop.

Select an option

Save wethu/e082a9723cff63fc7781 to your computer and use it in GitHub Desktop.
typedef NS_ENUM(NSInteger, MySwitchType) {
MyUserDefaultPreference1,
MyUserDefaultPreverence2
}
- (void)someSwitchSetup {
UISwitch *aSwitch = [UISwitch new];
aSwitch.tag = MyUserDefaultPreference1; // Could be MyUserDefaultBackgroundOn // BackgroundOff etc
[aSwitch addTarget:self selector:@selector(tapForUserDefaultChange:) forState:UIStateEventChanged]; // I cant remember the state change off the top of my head
}
- (void)tapForUserDefaultChange:(UISwitch *)aSwitch {
switch(aSwitch.tag) {
case MyUserDefaultPreference1:
// handle preference change
break;
case MyUserDefaultPreference2:
// handle preference change for 2
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment