Skip to content

Instantly share code, notes, and snippets.

@amichnia
Created February 16, 2019 14:44
Show Gist options
  • Save amichnia/577f18345fc79d8b28f50f6f97167169 to your computer and use it in GitHub Desktop.
Save amichnia/577f18345fc79d8b28f50f6f97167169 to your computer and use it in GitHub Desktop.
protocol SomeProtocol {
init()
}
class SomeClass: SomeProtocol {
...
}
// This will work
let instance: SomeProtocol = SomeClass.init()
// This won't work
let instance: SomeProtocol = SomeProtocol.init()
// Surprisingly, this also works
var type: SomeProtocol.Type! // Expose from Swift
type = SomeClass.self // Move it to ObjC!
let instance: SomeProtocol = type.init() // Use in Swift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment