문제

I have two files independant on each other.

Let's just call it Class1 and Class2.

In Class1, I need Class2, and in Class2 I need Class1.

I have a prefix file where I include all my files, and I get some syntax errors because I do

#import "Class1.h"
#import "Class2.h"

How would I define both of them so they can use each other?

What am I doing wrong?

도움이 되었습니까?

해결책

Look into using a forward declaration. Replace the #import of Class2 in Class1 with @class Class2; and move this #import statement to the implementation Class1.m (and vice versa).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top