Hi there,
I'm very new to Mac programming and I'm using XCode to build my application.
I have this code in my implementation file:
But when my timer fires, I can't seem to access my string anymore. It's like it got automatically dealloc-ed.
This is the header file:
What's wrong with my code?
I'm very new to Mac programming and I'm using XCode to build my application.
I have this code in my implementation file:
Code:
- (void)awakeFromNib
{
string = @"Hello World";
timer = [NSTimer scheduledTimerWithTimeInterval:5.0
target:self
selector:@selector(doSomething)
userInfo:nil
repeats:YES];
}
-(void)doSomething
{
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert setMessageText:string]; <<< This line crashes with EXC_BAD_ACCESS error
[alert runModal];
}
But when my timer fires, I can't seem to access my string anymore. It's like it got automatically dealloc-ed.
This is the header file:
Code:
#import <Cocoa/Cocoa.h>
@interface MyClass : NSObject <NSApplicationDelegate>
{
@private
NSString* string;
NSTimer* timer;
}
-(void)doSomething;
@end
What's wrong with my code?