Skip to content

Instantly share code, notes, and snippets.

@bsneed
Created January 7, 2017 18:41
Show Gist options
  • Save bsneed/d95fff67b295a3149226810396892dd5 to your computer and use it in GitHub Desktop.
Save bsneed/d95fff67b295a3149226810396892dd5 to your computer and use it in GitHub Desktop.
Swift-test: Protocol conformance and generics test
protocol Proto1 {
var someInt: Int { get set }
}
protocol Proto2 {
var someInt2: Int { get set }
}
struct AStruct: Proto1, Proto2 {
var someInt: Int = 0
var someInt2: Int = 0
}
protocol AProto: Proto1, Proto2 { }
func check<T1, T2>(_: T1.Type, _: T2.Type) {
// why does this return false?!
let conforms = T1.self is T2.Type
print("\(T1.self) conforms to \(T2.self)?: \(conforms)")
}
check(AStruct.self, Proto2.self)
check(AProto.self, Proto2.self)
print("\n")
print("\(AStruct.self) conforms to \(Proto2.self): \(AStruct.self is Proto2.Type)")
print("\(AProto.self) conforms to \(Proto2.self): \(AStruct.self is Proto2.Type)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment