당신은 클래스가 다음과 같이 서로 참조 할 수 있습니다 개체 자체 포인터를 가질 필요가 ClassB.h :
@class ClassA; // let the compiler know that there is a class named "ClassA"
@interface ClassB : NSObject {
ClassA *objectA;
}
@property (nonatomic, assign) ClassA *objectA; // "child" object should not retain its "parent"
@end
ClassA.m :
#import "ClassA.h"
#import "ClassB.h"
@implementation ClassA
@synthesize objectB;
- (id)init {
if (self = [super init]) {
objectB = [[ClassB alloc] init];
objectB.objectA = self;
}
return self;
}
@end
ClassB.m :
#import "ClassA.h"
#import "ClassB.h"
@implementation ClassB;
@synthesize objectA;
- (id)init {
if (self = [super init]) {
// no need to set objectA here
}
return self;
}
@end
이 문제의 제목이 더 좋은 말로 할 수 있습니까? 이것은 내가 찾고 있던 것이었지만, 제목으로 찾기가 어려웠습니다. 나는 다른 사람들의 질문을 편집하기에 충분한 담당자가 없다. – Drarok