title: Custom sound effect variable must be defined as a property?
body: <p>I created a custom class to handle sound effects in my app. While implementing the code, it didn't work at all as a local variable. I defined it as a property, and it worked just fine. Is there a way for me to be able to just use a local variable when using the class?</p>
  
  <p>SoundEffect.h</p>
  
  <pre><code>@interface SoundEffect : NSObject
  
  - (id)initWithSoundNamed:(NSString *)soundName;
  - (void)play;
  - (void)pause;
  
  @property (strong, nonatomic) AVAudioPlayer *player;
  @property (strong, nonatomic) NSString *soundName;
  
  @end
  </code></pre>
  
  <p>SoundEffect.m</p>
  
  <pre><code>@implementation SoundEffect
  
  - (id)initWithSoundNamed:(NSString *)soundName {
      self = [super init];
      if (self) {
          self.soundName = soundName;
          [self initialize];
      }
      return self;
  }
  
  - (void)initialize {
      NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@.mp3", [[NSBundle mainBundle] resourcePath], self.soundName]];
      NSError *error;
      self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&amp;error];
      if (self.player == nil) {
          NSLog(@"%@", error.localizedDescription);
      }
  }
  
  - (void)play {
      [self.player play];
  }
  
  - (void)pause {
      [self.player pause];
  }
  
  @end
  </code></pre>
  
  <p>Implementation</p>
  
  <pre><code>self.effect = [[SoundEffect alloc] initWithSoundNamed:@"laserShot"];
  [self.effect play];
  </code></pre>