Skip to content

Instantly share code, notes, and snippets.

@Wassmd
Created June 11, 2020 19:45
Show Gist options
  • Save Wassmd/4154b3cab49c33ca161564a77ee9ac71 to your computer and use it in GitHub Desktop.
Save Wassmd/4154b3cab49c33ca161564a77ee9ac71 to your computer and use it in GitHub Desktop.
import UIKit
class Widget {
let name: String
required init(name: String) {
self.name = name
}
}
func createWidget<T: Widget>(ofType: T.Type) -> T {
let widget = T.init(name: "Roq")
return widget
}
let a = createWidget(ofType: Widget.self)
print("\(a.name)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment