title: Obj C: Checking against an integer in NSUserDefaults
body: <p>Here's my situation - lets see if any coding geniuses out there can help me out!</p>
  
  <p>My situation is thus:</p>
  
  <p>I have an integer stored in NSUserDefaults by the name of @"scifi1" - it could be one of....say 250+ values - non sequential, but all known (i.e. it's from multiple choice)</p>
  
  <p>I need to check the value of said integer and dependent on what it is perform a different action.</p>
  
  <p>Now, my code as it stands is thus </p>
  
  <pre><code>if ([[NSUserDefaults standardUserDefaults] integerForKey:@"scifi1"] == 040){
              [self spaceup];
          }
          if ([[NSUserDefaults standardUserDefaults] integerForKey:@"scifi1"] == 10040){
              [self spaceup];
              [self ctrlup];
          }
          if ([[NSUserDefaults standardUserDefaults] integerForKey:@"scifi1"] == 20040){
              [self spaceup];
              [self altup];
          }
  </code></pre>
  
  <p>And while this works, once you've added in dozens more the code becomes 
  a) Very long
  b) When done for several different methods, too long for the iPhone to reasonably handle, and in fact Xcode throws out a GCC 4.2 error telling me so.</p>
  
  <p>So what's the best way to check this out? there must be a better way then repeated 'if' statements.</p>
  
  <p>I tried setting up a switch/case style setup but as the integers aren't constants it seemed unhappy with this - and to be honest, I'm not sure having switch/cases are any better in the long run for me than having multiple if statements.</p>
  
  <p>Anyone got any sharp ideas?</p>
  
  <p>Edit:</p>
  
  <p>Ok I've tried this as an experiment.</p>
  
  <pre><code>-(void)checkandrunup { 
      if (tempInt == 040){
          [self spaceup];
      }
      if (tempInt == 10040){
          [self spaceup];
          [self ctrlup];
      }
      if (tempInt == 20040){
          [self spaceup];
          [self altup];
      }
      if (tempInt == 30040){
          [self spaceup];
          [self shiftup];
      }}
  
  
  -(IBAction)torpup{
      //If to check for edit and display popover
      if ([[NSUserDefaults standardUserDefaults] boolForKey:@"viewEdit"] == YES) {
  
      }
      else {
          NSInteger tempInt = [[NSUserDefaults standardUserDefaults] integerForKey:@"scifi1"];
  
  
  
  
      }
          //First Sound
          if([[NSUserDefaults standardUserDefaults] boolForKey:@"viewHidden"] == YES) {
              NSString *path = [NSString stringWithFormat:@"%@%@",
                                [[NSBundle mainBundle] resourcePath],
                                @"/beep1.WAV"];
              SystemSoundID soundID;
              NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
              AudioServicesCreateSystemSoundID((CFURLRef)filePath, &amp;soundID);
              AudioServicesPlaySystemSound(soundID);  }
          //Second Sound
          else {
              NSString *path = [NSString stringWithFormat:@"%@%@",
                                [[NSBundle mainBundle] resourcePath],
                                @"/beep2.WAV"];
              SystemSoundID soundID;
              NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
              AudioServicesCreateSystemSoundID((CFURLRef)filePath, &amp;soundID);
              AudioServicesPlaySystemSound(soundID);
          }
      }
  </code></pre>
  
  <p>However the tempInt doesn't pass through from Torpup to checkandrunup - is there a way to get this to happen?</p>