I want to load JSON file to swift playground in two type, but it seems a bit confusing because after adding the astronaout.json file (in the first line) it gives the error "top level statement cannot begin with a closure expression", I don't know how to fix it, 2.error is missions. json file (on line 3) 'consecutive statements on a line must be separated by ";".
Any idea how to fix that?
I can’t show the whole code of this files cuz it’s 369 line*
And here is the bundle-decodable code;
import Foundation
extension Bundle {
func decode(_ file: String) -> [String: Astronaut] {
guard let url = self.url(forResource: file, withExtension: nil) else {
fatalError("failed to locate \(file) in bundle")
}
guard let data = try? Data(contentsOf: url) else {
fatalError("failed to load \(file) from bundle")
}
let decoder = JSONDecoder()
guard let loaded = try? decoder.decode([String: Astronaut].self, from: data) else {
fatalError("failed to decode \(file) from bundle")
}
return loaded
}
}