Post

Replies

Boosts

Views

Activity

Argument passed to call that takes no arguments help
here is my code. extension Bundle { func decode<T: Decodable>(file: String) -> T { guard let url = self.url(forResource: file, withExtension: nil) else { fatalError("Could not find \(file) in bundle.") } guard let data = try? Data(contentsOf: url) else { fatalError("Could not load \(file) from bundle.") } let decoder = JSONDecoder() guard let loadedData = try? decoder.decode(T.self, from: data) else { fatalError("Could not decode \(file) from bundle.") } return loadedData } } I am having issues on these lines. guard let data = try? Data(contentsOf: url) else { fatalError("Could not load \(file) from bundle.") } Someone please help. Thank you!
3
0
956
Jul ’23
Not able to decode JSON
Getting error " Thread 1: Fatal error: Could not decode sanantoniotx.json from bundle." Here is my code. // MARK: - Welcome struct Welcome: Codable { var status: String var urgentAdsHTML, data: [AdInfo] } // MARK: - AdInfo struct AdInfo: Codable { var aid, bname, bcity: String? var bstate: Bstate? var distance: String? var cangap: String? var vip: Int? var photo: [String: String]? var adsTitle, adsMsg, status: String? var urgentAdsHTML: [AdInfo]? enum CodingKeys: String, CodingKey { case aid, bname, bcity, bstate, distance, cangap, vip, photo case adsTitle case adsMsg case status, urgentAdsHTML } static let allAds: [AdInfo] = Bundle.main.decode(file: "sanantoniotx.json") static let sampleAd: AdInfo = allAds[0] } enum Bstate: String, Codable { case tx = "TX" } extension Bundle { func decode<T: Decodable>(file: String) -> T { guard let url = self.url(forResource: file, withExtension: nil) else { fatalError("Could not find \(file) in bundle.") } guard let data = try? Data(contentsOf: url) else { fatalError("Could not load \(file) from bundle.") } let decoder = JSONDecoder() guard let loadedData = try? decoder.decode(T.self, from: data) else { fatalError("Could not decode \(file) from bundle.") } return loadedData } } receiving the error at. fatalError("Could not decode \(file) from bundle.") Id be very thankful if anyone can help.
2
0
675
Jul ’23
NavigationView and ScrollView = Extra Padding?
Im having an issue with my View. When ever i want to put it inside of a ScrollView there is extra padding that appears. I tested to find the cause of it but to no luck. Here is the code for it : NavigationView{ NavigationLink(destination: HiringAdPage(favorite: true)) { HiringAds() } .buttonStyle(PlainButtonStyle()) } the ScrollPart of it : ScrollView{ VStack(spacing: 0) { ForEach(0..<5) {index in HiringAdsView() } } } Someone please help been trying for a while now..
1
0
496
Jul ’23