Hello
I want to make universal json exporter structure, and Swift drop my venture.
The code below
import Foundation
public protocol Sizeble {
var weight: Double { get }
var widht: Double { get }
var height: Double { get }
}
public struct Bike: Sizeble {
public var weight: Double = 100.0
public var widht: Double = 15
public var height: Double = 5
public init() {}
}
public struct ExportWraper<Base>{
public var base: Base
public init(base: Base) {
self.base = base
}
}
extension ExportWraper where Base: Sizeble {
public struct Export: Codable {
public let weight: Double
public let width: Double
public let height: Double
init(base: Base) {
weight = base.weight
width = base.widht
height = base.height
}
}
public var export: Export { return Export(base: base) }
}
let bike = Bike()
let wraper = ExportWraper(base: bike)
let exporter = wraper.export
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
do {
let data = try encoder.encode(exporter)
error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=EXC_I386_GPFLT).
The process has been left at the point where it was interrupted, use "thread return -x" to return to the
state before expression evaluation.
} catch let error {
print(error)
}
What I do wrong?