I’m trying to use a class as a key in an NSDictionary. I looked at the answer to this question and what I have is pretty much the same; I’m using setObject: forKey:. However, XCode complains, saying Incompatible pointer types sending 'Class' to parameter of type 'id<NSCopying>'. The call I have is:
[_bugTypeToSerializerDictionary setObject: bugToStringSerializer
forKey: [bugToStringSerializer serializedObjectType]];
bugToStringSerializer is an instance of BugToStringSerializer whose concrete implementations implement serializedObjectType. An example of a concrete implementation looks like this:
- (Class) serializedObjectType {
return [InfectableBug class];
}
What am I doing wrong here?
(It seems that classes do conform to
NSCopying, however their type is notid <NSCopying>.) Edit: classes do not conform to protocols. Of course the essential is that classes respond to thecopyandcopyWithZone:messages (and that’s why you can safely ignore the warning in this case). Their type is still notid <NSCopying>.) That’s why the compiler complains.If you really don’t want that ugly warning, just perform an explicit type conversion: