I'm new to objective-c so please bear with me.
I'll keep my clothes on for this one--if you don't mind.
One way to achieve what you want is through 'composition', which means write A so that it has a member variable that is an instance of B. Then A can use that instance of B to call methods in B:
A.h:
#import <Cocoa/Cocoa.h>
#import "B.h"
@interface A : NSObject {
B* my_b;
}
- (id)init:(B*)b;
- (void)methodA;
@end
.
A.m:
#import "A.h"
@implementation A
- (id)init:(B*)b
{
if (![super init])
{
return nil;
}
my_b = b;
return self;
}
- (void)methodA
{
[my_b methodB];
}
@end
.
B.h:
#import <Cocoa/Cocoa.h>
@interface B : NSObject {
}
- (void)do_stuff;
- (void)methodB;
@end
.
B.m:
#import "B.h"
#import "A.h"
@implementation B
- (void)do_stuff
{
A* a = [[A alloc] init:self];
[a methodA];
}
- (void)methodB
{
NSLog(@"hello");
}
@end
===
Because you wrote:
[classB methodB];
...maybe you want to call a class method in B.
A.h:
#import <Cocoa/Cocoa.h>
#import "B.h"
@interface A : NSObject {
}
- (void)methodA;
@end
A.m:
#import "A.h"
#import "B.h"
@implementation A
- (void)methodA
{
[B classMethodB];
}
@end
B.h:
#import <Cocoa/Cocoa.h>
@interface B : NSObject {
}
+ (void)classMethodB;
- (void)do_stuff;
@end
B.m:
#import "B.h"
#import "A.h"
@implementation B
- (void)do_stuff
{
A* a = [[A alloc] init];
[a methodA];
}
+ (void)classMethodB //Note the '+'
{
NSLog(@"hello");
}
@end