I have a string (currently defined in my .h file) that I'd like to fill and reuse in my .m file.
Here's the setup:
- User clicks btnA in my interface
- btnA runs a method (buttonAClicked) that sets the NSString's value to "foo"
- USer clicks btnB in my interface
- btnB runs a method (buttonBClicked) that returns the value of the NSString (eg: "foo")
- User clicks btnA again and the method updates the NSString "a new value"...
- Profit!
Here's some code:
/* Modal_TestAppDelegate.h */
// in the @interface block //
@public
NSString *countOfMatches;
// in the main area of the .h //
@property (nonatomic, readwrite, reatain) NSString *countOfMatches;
/* Modal_TestAppDelegate.m */
@synthesize countOfMatches;
-(void)applicationDidFinishLaunching:(UIApplication *)application{
... other code ...
self.countOfMatches = [[NSString alloc] initWithFormat:@"0"];
}
-(void)updateButtonClicked:(id)sender{
countOfMatches = @"1";
NSLog(@"countOfMatches is now: %@",countOfMatches);
}
-(void)readButtonClicked:(id)sender{
NSLog(@"I wonder what countOfMatches is set to now? %@",countOfMatches); // CRASH!
}
the "readButtonCicked area is where I'm crashing - it looks like I can't read the countOfMatches string anymore.
Any ideas on how I can simply reuse a "variable" throughout a single class (if I'm calling the .m implementation a "class" correctly - this is my first attempt and I'm kinda ripping pages out of the several Xcode and iPhone SDK books I have).
Thanks!