Question

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?

Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top