Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C import circle warnings

I'm doing a dots game on the iphone for fun ( just simulator) and learning. this is the game where there are dots and you connect them with "pathways", if you close the square that 4 dots create, you "win" the square.

Now I'm getting some warnings and I'd like to understand how to remove them. First this is te situation. I have a class that represents the connection between 2dots, called Pathway. I have a class called circuit that represent the circuit created by 4 pathways. so class Circuit has an NSMUtable array of 4 Pathways

and each pathway has an NSMutable array of at most 2 circuits ( each pathway can belong to at the most 2 circuits). So as you can see there is an import cycle.

I used the @class to include on one of the classes the other because otherwise I'd get errors on compile.

It all works but I'm getting warnings on one of the classes because it can't see the methods for the other.

how can I work around this and what is the proper way to work with these kinds of problems.

like image 628
cromestant Avatar asked Jun 27 '26 07:06

cromestant


1 Answers

File pathway.h

@class Circuit;

@interface Pathway {
}
...
@end;

File pathway.m

#import "circuit.h"
#import "pathway.h"

...

File circuit.h

@class Pathway;

@interface Circuit {
}
...
@end;

File circuit.m

#import "pathway.h"
#import "circuit.h"

...

You don't usually need the full declaration of a dependent class in the header declaring another class. You need the declaration in the implementation files, though. So, split things up.

like image 71
Dirk Avatar answered Jun 28 '26 22:06

Dirk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!