Reputation: 105
I have a protocol in Objective-C. I am, in another class, trying to add an object that implements this protocol to an NSMutableDictionary.
- (void) addValue:(NSString*)myString withObject:(id<MyProtocol>*)protocolThing
{
[dictionary insertValue:protocolThing inPropertyWithKey:myString];
}
This gives me an error saying "Implicit conversion of an indirect pointer to an Objective-C pointer to 'id' is disallowed with ARC"
How can I do this?
This is coming from Java, where I can declare an interface and then treat objects that implement that interface as regular objects and then add them to HashMaps.
Upvotes: 1
Views: 498
Reputation: 7344
When using id
you do not use a *
Use this:
- (void) addValue:(NSString*)myString withObject:(id<MyProtocol>)protocolThing
Upvotes: 1
Reputation: 28688
Your problem is that id<MyProtocol>
is already a pointer type. Change your signature to
- (void) addValue:(NSString*)myString withObject:(id<MyProtocol>)protocolThing
And it will work fine.
Upvotes: 2