Skip to content

Instantly share code, notes, and snippets.

@douglashill
douglashill / covariance.m
Last active November 25, 2016 14:53
A quick look at variance with Objective-C generics. `NSSet` is covariant on its `ObjectType`, while `NSHashTable` is invariant. Contravariance is also supported.
@import Foundation;
@interface ContravariantCollection<__contravariant ObjectType> : NSObject
@end
@implementation ContravariantCollection
@end
void stringSetThing(NSSet<NSString *> *set) {
}