Last active
January 6, 2023 22:45
-
-
Save marknorgren/7cfd738d8f3b8096f456facf6f58c70b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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