I am making an app. The user starts the app, clicks "play" and it loads another ViewController. Inside that ViewController I have one start button and one Option button. The start button, starts the Game and plays one song when clicked. But in the options menu I have more songs to choose. When a user chooses one, the default start button gets hidden and then the start button that has the IBAction to play the specified song by the user appears. And when the user clicks it it starts playing the song the user selected. Again, I repeat, there's got to be an easier way to do it, but I'm just getting started so I made like 6 buttons, and each one plays a different song. Only one is loaded depending on the song the user selected and the other are hidden. My question is, I wanted to make a button or something like it that the user could select his own default music. Like every time the ViewController loads, it automatically loads the right IBAction or the right button and plays the user's default song. The only thing I heard is NSUserDefaults but I don't think it fits what I want to do...maybe I'm wrong... If anybody could help me I would really be much appreciated. Thank you all!
2 Answers
0
votes
You can use nsuserdefaults to save user preferences in a way like this:
NSString *valueToSave = @"someValue";
[[NSUserDefaults standardUserDefaults]
setObject:valueToSave forKey:@"preferenceAction"];
to get it back:
NSString *savedValue = [[NSUserDefaults standardUserDefaults]
stringForKey:@"preferenceAction"];