ios - How to overcome a #import loop? -


imagine have 2 header files: somefilea.h , somefileb.h

somefilea.h includes somefileb.h, , somefileb.h includes somefilea.h.

this creates loop , confuse compiler. how can overcome this?

you should "forward declare" classes. tells compiler class exists, without need import it.

somefilea.h

@class somefileb  // <-- "forward declares somefileb" @interface somefilea  @property (nonatomic, strong) somefileb *somefileb; ... @end 

somefilea.m

#import "somefileb.h" @implementation somefilea ... @end 

and same thing, other way around in somefileb

somefileb.h

@class somefilea  // <-- "forward declares somefilea" @interface somefileb  @property (nonatomic, strong) somefilea *somefilea; ... @end 

somefileb.m

#import "somefilea.h" @implementation somefileb ... @end 

if don't use class in header, don't need forward declare it.

@interface somefilea //i took out property somefileb.. no need @class anymore. ... @end 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -