Skip to content

Instantly share code, notes, and snippets.

@drodriguez
Created December 6, 2014 00:10
Show Gist options
  • Save drodriguez/64c470cf59eae85767b1 to your computer and use it in GitHub Desktop.
Save drodriguez/64c470cf59eae85767b1 to your computer and use it in GitHub Desktop.
Computed variable to return type conforming protocol.
protocol TestProtocol {
}
class TestClass : TestProtocol {
}
class TestClass2 {
}
struct Test {
var a: TestClass.Type {
get {
return TestClass.self
}
}
var b: TestProtocol.Type {
get {
return TestClass.self
}
}
var c: TestProtocol.Type {
get {
return TestClass2.self // Type 'TestClass2' does not conform to protocol 'TestProtocol'
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment