1

I am trying to create instance of classes in each class. But xCode does not give permission.

For example;

I have class A and I have created instance of class B, if I create instance of A in B. It shows an error that the class is not found do you mean this class.So, i am not able to add it.

Could you please explain this situation and is there a solution for it?

Thank you

erdemgc
  • 1,701
  • 3
  • 23
  • 43
  • 1
    Can you show your codes ? – Raptor Feb 12 '14 at 07:56
  • 2
    Don't forget to `#import` the class A header (.h) into the class B implementation (.m) and the class B header into class A implementation. And use `@class ClassB` in your .h if you want to use them as properties. See: http://stackoverflow.com/questions/322597/class-vs-import – Matthias Bauch Feb 12 '14 at 07:58

1 Answers1

2

You need to #import each class .h file into the other class .m file. If you import each .h into the .h files then you will have a circularity which won't work. If you need a public property for the instances then use @class instead of #import in the .h files (which is good practice anyway to limit scope and visibility).

Wain
  • 118,658
  • 15
  • 128
  • 151