Some time ago, I asked a question involving decoding JSON. I am using this JSON to create an entry in a list and decide whether or not to have a checkbox ticked. My previous question asked how to decode the JSON, and I have this code which looks useful (below), but to be honest, I have no idea what to do with.
Where would I put this within a SwiftUI file where I could loop through each piece of JSON in this array and add an entry into a SwiftUI?
I have experience with Python, and I understand how it should be done, but am quite the beginner in swift...
My code:
struct Mod: Decodable {
let id: String
let display: String
let description: String
let url: String?
let config: Bool?
let enabled: Bool?
let hidden: Bool?
let icon: String?
let categories: [String]?
// let actions: Array<OptionAction>?
// let warning: ActionWarning?
}
let modsURL = URL(string: "https://raw.githubusercontent.com/nacrt/SkyblockClient-REPO/main/files/mods.json")!
let task = URLSession.shared.dataTask(with: url) { (data, _, error) in
if let error = error { print(error); return }
do {
let result = try JSONDecoder().decode([Mod].self, from: data!)
print(result)
} catch {print(error)}
}
task.resume()
let mods_test: () = importJSON(url: modsURL)
let enableds = mods_test.map {$0.enabled}
If there is anything wrong with this question, please tell me! Thanks in advance for the help.
