Aswath
Aswath

Reputation: 1510

Two @implementation in a file; The bottom implementation methods are not visible in the top implementation?

I have two implementation in a single file. Like the one below. How do I access the second's method in the first? If I try to do that the compiler throws an unknown selector error.

I know that in C you have to have methods which have to have hierarchy in definitions to be able to build. Is this the same in ObjectiveC also? Are there any alternatives to this other than defining the second implementation above the first?

@implementation BaseClass

  -(void)someMethod {
   XCUIElementQuery *elementQuery = [[XCUIApplication alloc] init].tables
   [elementQuery anotherMethod];  //How do I use the category method here?
  }
@end


@implementation XCUIElementQuery (BaseClassCategory)

  -(void)anotherMethod {
   //do something
  }
@end

Upvotes: 0

Views: 38

Answers (2)

TyR
TyR

Reputation: 712

At the top of the file, just declare an interface for XCUIElementQuery like so:

@interface XCUIElementQuery (XCUIElementQuery_private)
-(void)anotherMethod;
@end

Upvotes: 1

rmaddy
rmaddy

Reputation: 318954

Just swap the two sets of implementations.

@implementation XCUIElementQuery (BaseClassCategory)

-(void)anotherMethod {
   //do something
}
@end

@implementation BaseClass

-(void)someMethod {
    XCUIElementQuery *elementQuery = [[XCUIApplication alloc] init].tables
    [elementQuery anotherMethod];  //How do I use the category method here?
}

@end

Upvotes: 0

Related Questions