I know this isn't totally SwiftUI related but please bear with me.
Using this excellent video by Karin Prater https://www.youtube.com/watch?v=ZHK5TwKwcE4
I have built an app using the spaceX API here : https://api.spacexdata.com/v4/launches using the same techniques as Karin.
I want to mock some data for previews. But I am stuck by the complexity of the returned data.
struct Launch: Codable, Identifiable {
let links: Links?
let success: Bool?
let details: String?
let name, dateUTC: String?
let dateUnix: Int?
let dateLocal: String?
let launchLibraryID: String?
let id: String
enum CodingKeys: String, CodingKey {
case links
case success,details
case name
case dateUTC = "date_utc"
case dateUnix = "date_unix"
case dateLocal = "date_local"
case launchLibraryID = "launch_library_id"
case id
}
struct Links: Codable {
let patch: Patch
enum CodingKeys: String, CodingKey {
case patch
}
}
// MARK: - Patch
struct Patch: Codable {
let small, large: String?
}
Some example data returned with debug/print
SpaceX_API_Demo.Launch(links: Optional(SpaceX_API_Demo.Links(patch: SpaceX_API_Demo.Patch(small: Optional("https://images2.imgbox.com/94/f2/NN6Ph45r_o.png"), large: Optional("https://images2.imgbox.com/5b/02/QcxHUb5V_o.png")))), success: Optional(false), details: Optional("Engine failure at 33 seconds and loss of vehicle"), name: Optional("FalconSat"), dateUTC: Optional("2006-03-24T22:30:00.000Z"), dateUnix: Optional(1143239400), dateLocal: Optional("2006-03-25T10:30:00+12:00"), launchLibraryID: nil, id: "5eb87cd9ffd86e000604b32a"), SpaceX_API_Demo.Launch(links:
func successState() -> Launch {
let launch = Launch(links: <#T##Links?#>, success: true, details: "", name: "", dateUTC: "", dateUnix: 1234567, dateLocal: "", launchLibraryID: "", id: "")
}
I have no idea how to fill the initializer for Links ...
Thanks for any help!