Created
May 28, 2021 18:09
-
-
Save nerzh/fdcecc149d4905ef8c6979e8d0d46d32 to your computer and use it in GitHub Desktop.
Metaprogramming in swift
This file contains 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
struct S: Encodable {} | |
extension Encodable { | |
var nnn: Int { return 1 } | |
} | |
protocol B { | |
static func test<T: Encodable>(_ value: T) -> Int | |
} | |
class C: B { | |
static func test<T: Encodable>(_ value: T) -> Int { | |
print("VALUE IS \(value)") | |
return value.nnn | |
} | |
} | |
func fatality(_ s: S? = nil) -> Int { | |
return C.test(s) | |
} | |
let s: S? = nil | |
let result = fatality(s) | |
print("RESULT: \(result)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment