Created
June 16, 2021 09:06
-
-
Save intan1907/faebd88790fa32521c16cecd4937c51e to your computer and use it in GitHub Desktop.
RecipeBaseClass with widgetURL property
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public struct RecipeBaseClass: Codable, Hashable { | |
// ... | |
public var ingredients: [RecipeIngredients]? | |
public var originalURL: String? | |
public var imageURL: String? | |
public var steps: [String]? | |
public var name: String? | |
public var time: Int? | |
public var serving: String? | |
public var widgetURL: URL? | |
public init(from decoder: Decoder) throws { | |
let container = try decoder.container(keyedBy: CodingKeys.self) | |
ingredients = try container.decodeIfPresent([RecipeIngredients].self, forKey: .ingredients) | |
originalURL = try container.decodeIfPresent(String.self, forKey: .originalURL) | |
imageURL = try container.decodeIfPresent(String.self, forKey: .imageURL) | |
steps = try container.decodeIfPresent([String].self, forKey: .steps) | |
name = try container.decodeIfPresent(String.self, forKey: .name) | |
time = try container.decodeIfPresent(Int.self, forKey: .time) | |
serving = try container.decodeIfPresent(String.self, forKey: .serving) | |
widgetURL = URL(string: "recipe://\((name ?? "").addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? (name ?? "").filter { $0.isWhitespace })") | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment