Issue #306
let json: [String: Any] = [
"id": "123",
"name": "Thor",
"isInMarvel": true
]
let data = try JSONSerialization.data(withJSONObject: json, options: [])
let string = String(data: data, encoding: .utf8)!
return try Hero(jsonString: string)
If we use withValue
from How to simplify struct mutating in Swift then we can mock easily
extension Hero {
static func mock() -> Hero {
return withValue(Hero()) {
$0.id = "123"
$0.name = "Thor"
$0.isInMarvel = true
}
}
}