@protocol protoA <NSObject>
@end
@interface objA : NSObject<protoA> {
@private
}
@end
@implementation objA
@end
@protocol protoB <NSObject>
-(void) foo: (id <protoA> *) par;
@end
@interface objB : NSObject<protoB>
-(void) foo: (id <protoA> *) par;
@end
@implementation objB
-(void) foo: (id <protoA> *) par
{
//...
}
@end
in some other class method i use it this way:
objB *obj1 = [[objB alloc] init];
objA *obj2 = [[objA alloc] init];
[obj1 foo: obj2];
I have compiler error: "Implicit conversion of an Objective-C pointer to '__autoreleasing id*' is disallowed with ARC
What is the proper way to do get this functionality ?
id
already is a pointer-type, use just id<Protocol>
instead of id<Protocol>*
.
id
is a pointer already, drop *
:
-(void) foo: (id <protoA>) par
If you want to specify type and protocol, you can use this form:
- (void)method:(MONType<MONProtocol>*)param;
If you want an opaque objc type (id
) and protocol, use this form:
- (void)method:(id<MONProtocol>)param;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With