I am getting crazy over this error. Compiler is saying out of scope for an instance NSSString variable. Never had this thing before and used thousands of NSString instance variables!
Here is my class .h file
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <CoreAudio/CoreAudioTypes.h>
#import "Snapshot.h"
@interface RecordAudioViewController : UIViewController <AVAudioRecorderDelegate, AVAudioPlayerDelegate> {
NSString *filename;
}
@property (nonatomic, retain) NSString *filename;
- (IBAction) recordAudio;
- (IBAction) playAudio;
@end
Variable is synthesized properly. I initalize filename variable in viewDidLoad method. I want to use it in IBAction method recordAudio, but compiler always says out of scope? Why is that, is this a bug or something?
Here is .m code. viewDidLoad method where I set the filename instance variable:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *tmpDir = NSTemporaryDirectory();
filename = [NSString stringWithFormat: @”%.0f.%@”, [NSDate timeIntervalSinceReferenceDate] * 1000.0, @”caf”];
NSLog(filename);
}
And the IBAction method
- (IBAction) recordAudio
{
NSLog(filename); // here I get out of scope message when moving over with mouse cursor and when steping over this line EXC_BAD_ACCESS
}
The entire .m file can be seen here: http://pastie.org/1021993
Actually, if you set filename = [NSString stringWithFormat…], the autoreleased result is NOT retained.
However, if you use self.filename = [NSString stringWithFormat…] it WILL retain the string. Kinda looks like the string is getting released out from under you because you’re not retaining it.