0

This is a simplified structure of my app

A.h

#import "B.h"

@interface A : NSObject {

B *b1;

}

B.h

@interface B : NSObject {
}

That works fine, but now I need to create an array of A-s in B so this is what I have done

A.h

#import "B.h"

@interface A : NSObject {

B *b1;

}

B.h

#import "A.h"

@interface B : NSObject {

NSMutableArray *aArray;

}

-(void) addA: (A*) aTemp{
    [aArray addObject:aTemp];
}

-(NSMutableArray*) getArray{
    return aArray;
}

And surprisingly I am getting an error on the import A.h

Why is this happening?

Any clue?

Thanks

Andoxko
  • 1,021
  • 2
  • 12
  • 19
  • What error have you got? You don't have to import A.h in Interface B, because you don't call and A object. You can move it to Implementation B. – Greg Jan 22 '14 at 12:45
  • I have edited the question. Sorry I was trying to simplify it and I have simplified too much :) – Andoxko Jan 22 '14 at 12:52
  • You can add @class A; to B.h file and #import "A.h" to B.m file. If it doesn't work post your error. – Greg Jan 22 '14 at 12:55

2 Answers2

0

You cannot have mutual imports like this. But you don't need imports at all in this case. In A.h it is enough to add

@class B;

and in B.h you don't need any import.

Wojtek Surowka
  • 20,535
  • 4
  • 44
  • 51
0

Objective-c dosent allow for circular dependencies, I think this thread is the answer for you problem: Does Objective-C allow circular dependencies?

Community
  • 1
  • 1