tags:

views:

41

answers:

1

Hi, I have a protocol say

@protocol MyProtocol
-(void)mload 
@end

with a method mload, I also have ClassA which has implemented that protocol method ie mload.

@implementation ClassA
-(void)mload {
    NSLog(@"ClassA-mload");
}
@end

Now I need to call that method in another class say ClassB using an instance of ClassA. How to do that?

+4  A: 

In ClassB something like this, not sure how you're getting reference to ClassA obj but:

// obj is of type that implements protocol
id<MyProtocol> obj = [[ClassA alloc] init];
[obj load];


// should work as well because objective-c is dynamically typed so you can call
// any method on an object
id obj = [[ClassA alloc] init];
[obj load];
stefanB
Thanks for the reply i now tried it, this gives me a exception as NSInvalidArgumentException and [ClassB mload]:unrecognized selector sent to instance. How to solve the problem?
Cathy
Did you implement `mload` in `ClassB`?
mipadi
Hi stefanB now i got with the output..Thanks..
Cathy
hm ... I hope it works :)
stefanB