Playing with my code today,
I run this particular piece of code several times in minor variations throughout a particular class, I’m trying to streamline though. The difference in effect is minimal but changes the amount of code by a volume of hundreds or thousands of lines so would be a big personal win for me.
Essentially I have a value stored as an integer with a key of ‘codeKey’ and I want to insert the value of that key where the number 30061 currently resides. I’m at a bit of a loss how, can anyone help me out with this one?
I know I need to recall the value somehow and place it in but I’m not really sure how that would look.
if ([[NSUserDefaults standardUserDefaults] integerForKey:@"buttonID"] == 1) {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setInteger:30061 forKey:@"scifi1"];
[userDefaults synchronize];}
I take it you mean dynamically saving this information without duplicating the same code over and over. If that is correct, your solution will be something like this:
Now you can simply invoke
[self saveCodeKey:12345];Assuming the-saveCodeKey:method resides in the same class.Hope this helps !