Skip to content

Instantly share code, notes, and snippets.

@nerzh
Created May 28, 2021 18:09
Show Gist options
  • Save nerzh/fdcecc149d4905ef8c6979e8d0d46d32 to your computer and use it in GitHub Desktop.
Save nerzh/fdcecc149d4905ef8c6979e8d0d46d32 to your computer and use it in GitHub Desktop.
Metaprogramming in swift
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