Closed
Description
Example Code
import Foundation
class Base: Codable { }
class Child: Base { }
func dynamicType() -> Base.Type {
return Child.self
}
let data = "{}".data(using: .utf8)!
let classType = dynamicType()
let instance = try JSONDecoder().decode(classType, from: data)
print("type: \(instance) => \(type(of: instance))")
on macOS:
type: JSONDecoderExample.Child => Child
on Linux:
type: JSONDecoderExample.Base => Base
Metadata
Metadata
Assignees
Labels
No labels