Reputation: 93
@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 ?
Upvotes: 9
Views: 3734
Reputation: 104708
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;
Upvotes: 2
Reputation: 24439
id
is a pointer already, drop *
:
-(void) foo: (id <protoA>) par
Upvotes: 4
Reputation: 99092
id
already is a pointer-type, use just id<Protocol>
instead of id<Protocol>*
.
Upvotes: 15