Skip to content

Instantly share code, notes, and snippets.

@marknorgren
Last active January 6, 2023 22:45
Show Gist options
  • Save marknorgren/7cfd738d8f3b8096f456facf6f58c70b to your computer and use it in GitHub Desktop.
Save marknorgren/7cfd738d8f3b8096f456facf6f58c70b to your computer and use it in GitHub Desktop.
protocol A {
static func doSomething() -> String
static func aFuncWith(param: String) -> String
}
extension A {
static func aFuncWith(param: String = "default") -> String {
return param
}
}
struct B: A {
static func doSomething() -> String {
return "doin it!"
}
static func aFuncWith(param: String) -> String {
param
}
}
B.aFuncWith()
B.aFuncWith(param: "hello")
enum C: A {
static func doSomething() -> String {
return "doin it!"
}
}
class MyClass {
let aType: A.Type
init(aType: A.Type) {
self.aType = aType
}
func doSomething() -> String {
return aType.doSomething()
}
}
struct MyStruct {
let aType: A.Type
init(aType: A.Type = B.self) {
self.aType = aType
}
func doSomething() -> String {
return aType.doSomething()
}
}
let myClass = MyClass(aType: C.self)
print(myClass.doSomething())
let myStruct = MyStruct(aType: C.self)
print(myStruct.doSomething())
let myOtherStruct = MyStruct()
myOtherStruct.doSomething()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment