I am trying to receive the user selection from a segmented control and then save it to NSUserDefaults, i.e., if the first segment is selected then it saves the int “1” to NSUserDefaults, but if the second segment is selected then it saves the int “2” to NSUserDefaults.
Share
The easiest way is to use a binding. Bind the selected index of the control to the shared user defaults controller, and set the model key path to the preference key you want to use.
Edit to add: I see that you didn’t specify Mac or iOS. If it’s Mac, binding is definitely the easy way, whereas binding is not available on iOS.
The fact that segmented control values start at 0 is unimportant. You could bind selected tag rather than selected index, and then use any tag values you want.