I have two classes (Test1 and Test2) that each have a property (test2 and test1 respectively) pointing to an instance of the other class. This means that Test1.m must import Test2.h and Test2.m must import Test1.h. The .h files must also have a forward declaration. Unfortunately, this means that I cannot access the attributes of test2 and test1 with dot notation. I can access them with message passing, but I should be able to use either notation. How can I resolve this problem?
Related
Test1
//Test1.h
@class Test2;
@interface Test1 : NSObject {
Test2* test2;
int a1;
}
@property (nonatomic, retain) Test2* test2;
- (void)meth1;
@end
//Test1.m
#import "Test1.h"
#import "Test2.h"
@implementation Test1
@synthesize test2;
- (void)meth1{
test2.a2;//Request for member 'a2' in something not a structure or union
}
@end
Test2
//Test2.h
#import <Foundation/Foundation.h>
@class Test1;
@interface Test2 : NSObject {
Test1 *test1;
int a2;
}
@property (nonatomic, assign) Test1* test1;
- (void)meth2;
@end
//Test2.m
#import "Test2.h"
#import "Test1.h"
@implementation Test2
@synthesize test1;
- (void)meth2{
test1.a1;//Request for member 'a1' in something not a structure or union
}
@end
Adding properties for and synthesizing a1 & a2 seems to help.