0

I am confused about Cyclic dependencies. I have two .m file and I need used those two files in each other.

For example two files A.h/A.m and B.h/.m Now I have to access the variable of file A.h/.m into B.h/.m and the variable of file B.h/.m into A.h/.m I import A.h into B.h and B.h into A.h But it gives an error.

And ya I don't want to use Delegate file ! is there any way to do the same without Delegate file ?

Thanks..

Maulik
  • 19,348
  • 14
  • 82
  • 137

2 Answers2

2

You should probably place the #imports in the .m file instead of the .h You may need to forward declare the classes if you reference them in the .h

Alex Deem
  • 4,717
  • 1
  • 21
  • 24
  • ya error get solved but now the value of variable is null... the variable is NSMutableArray that is declared in A.h file and I am allocating memory in B.m class. I also tried to allocating memory in A.m file but still it shows null values.. – Maulik Mar 24 '11 at 05:40
  • @maulik I'd have to see the code to understand it. Perhaps start a new question, as I doubt it's a dependency problem anymore. – Alex Deem Mar 24 '11 at 12:25
2

From What is the difference between @class and #import

@class is used to avoid circular dependency... This prevents circular references where in one header A imports a second header B which(B) imports the first(A) which imports the second (B)and so on in an endless cycle....@class is generally used to ask compiler to look for its definition at runtime... especially when it resides in some static library..

Pls see this too

when and where to put @class declarations

Community
  • 1
  • 1
visakh7
  • 26,380
  • 8
  • 55
  • 69
  • ya error get solved but now the value of variable is null... the variable is NSMutableArray that is declared in A.h file and I am allocating memory in B.m class. I also tried to allocating memory in A.m file but still it shows null values.. – Maulik Mar 24 '11 at 06:31
  • I am not sure if u will be able to access values that way. the use of delegates is preferred to such purposes – visakh7 Mar 24 '11 at 06:33