Posts

Post not yet marked as solved
3 Replies
1k Views
so below is the part of the code (in SwiftUI) where local JSON file is used, I want to use remote JSON instead of local, could someone help?Source is (https://developer.apple.com/tutorials/swiftui/building-lists-and-navigation)so instead local landmarData.json I want to use https://lkakashv.github.io/landmarkData.json::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::{let landmarkData: [Landmark] = load("landmarkData.json") func load<T: Decodable>(_ filename: String) -> T { let data: Data guard let file = Bundle.main.url(forResource: filename, withExtension: nil) else { fatalError("Couldn't find \(filename) in main bundle.") } do { data = try Data(contentsOf: file) } catch { fatalError("Couldn't load \(filename) from main bundle:\n\(error)") } do { let decoder = JSONDecoder() return try decoder.decode(T.self, from: data) } catch { fatalError("Couldn't parse \(filename) as \(T.self):\n\(error)") } }}::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::Thank you
Posted
by lkakashv.
Last updated
.
Post not yet marked as solved
2 Replies
1.8k Views
So below is the part of the code (in SwiftUI) where local JSON file is used, I want to use remote JSON instead of local, could someone help?Source is (https://developer.apple.com/tutorials/swiftui/building-lists-and-navigation)so instead local landmarkData.json I want to use https://lkakashv.github.io/landmarkData.jsonlet landmarkData: [Landmark] = load("landmarkData.json") func load(_ filename: String) -> T { let data: Data guard let file = Bundle.main.url(forResource: filename, withExtension: nil) else { fatalError("Couldn't find \(filename) in main bundle.") } do { data = try Data(contentsOf: file) } catch { fatalError("Couldn't load \(filename) from main bundle:\n\(error)") } do { let decoder = JSONDecoder() return try decoder.decode(T.self, from: data) } catch { fatalError("Couldn't parse \(filename) as \(T.self):\n\(error)") } }Thank you
Posted
by lkakashv.
Last updated
.