title: Can I create a single object that's accessible by different methods?
body: <p>This might be a basic question, but I'm new to Cocoa and Objective-C and OOP in general, and I haven't been able to find an answer to this anywhere.</p>
  
  <p>In an app I'm writing, I want to play a sound file whenever the user presses a particular button.  I'm using NSSound for that and have no problem implementing it.  The problem is, I only know how to do it by creating a new NSSound object each time the button is pressed:  </p>
  
  <pre><code>- (IBAction)playSound:(id)sender {
      NSSound *sound = [[NSSound alloc] initWithContentsOfFile:kSoundFilePath byReference:YES];
      [sound play];
  }
  </code></pre>
  
  <p>This is an issue for me because if the user clicks the button repeatedly before the file finishes playing, it will create new instances of NSSound and they will all play on top of each other, which I don't want.   Is there a way that I can create the NSSound object outside of that method, and have the IBAction method for the button check to see if the NSSound is playing before telling it to play again?</p>