我得到以下错误:
无法读取数据,因为它已丢失.
When I run the following code:
struct Indicator: Decodable {
let section: String
let key: Int
let indicator: Int
let threshold: Int
}
var indicators = [Indicator]()
do {
if let file = Bundle.main.url(forResource: "indicators", withExtension: "json") {
indicators = try JSONDecoder().decode([Indicator].self, from: try Data(contentsOf: file))
}
} catch {
print(error.localizedDescription)
}
These are in a function, but I have removed them for clarity. I have a code block which is very similar in a different file (I copied this code from there and changed the names essentially) so I'm not sure why it's happening. The json file is valid json and has it's target properly set.
Thanks