I need to set a variable in Class A from Class B. To test this, I have a while loop running in Class A that continuously prints the variable via NSLog. However, no matter what I try, I cannot get Class B to update the variable in Class A in such a way that Class A can read the changes made by Class B. I am pretty sure I have everything hooked up properly in IB. Here's how I have things set up:
//Class A
@interface AppDelegate : NSObject {
NSString *teststring;
}
@property(readwrite,nonatomic,retain) NSString *teststring;
@end
@implementation AppDelegate
@synthesize teststring;
-(id)init{
self = [super init];
if(self) {
teststring = [[NSString alloc] init];
}
return self;
}
-(void)awakeFromNib
{
while(1){
NSLog(@"teststring is %@",teststring);
usleep(500000);
}
}
@end
//Class B
@class AppDelegate;
@interface otherClass : NSObject {
AppDelegate *appdel;
}
-(IBAction)doTest:(id)sender;
@end
@implementation otherClass
-(void)awakeFromNib
{
appdel = [[AppDelegate alloc] init];
}
-(void)doTest:(id)sender
{
appdel.teststring = @"Test";
NSLog(@"Set teststring to %@",appdel.teststring); //this works
}
@end