HomeiOS Developmentios - Sort '_' doesn't conform to protocol Decodable / Encodable

ios – Sort ‘_’ doesn’t conform to protocol Decodable / Encodable


I am attempting to retrieve some outcomes from the iTunes API and needed to jot down a struct for the APIResponse, and have a variable of sort ‘End result’, however it does not appear to be working (and am undecided how one can go about all of it, if I ought to use a distinct sort, scrap it, and so on).

struct APIResponse: Codable {
    var apiResults: End result
}

struct APIResult: Codable {
    var songName: String
    var songID: Int
    var collectionName: String
}

struct ContentView: View {
    @State var outcomes = [APIResult]()
    
    func loadData() async {
        // Step 1: Creating the URL we wish to learn.
        guard let url = URL(string: "https://itunes.apple.com/search?time period=john+mayer&entity=music") else {
            print("Invalid URL")
            return
        }
        
        // Step 2: Fetching the info for the URL.
        do {
            let (information, _) = attempt await URLSession.shared.information(from: url)
            
            if let decodedResponse = attempt? JSONDecoder().decode(APIResponse.self, from: information) {
                outcomes = decodedResponse.apiResults
            }
        } catch {
            print("Invalid information.")
        }
    }
    
    var physique: some View {
        Checklist(outcomes, id: .songID) { songItem in
            VStack(alignment: .main) {
                Textual content(songItem.songName).font(.headline)
                Textual content(songItem.collectionName)
            }
        }.process {
            await loadData()
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Am I going about it all of the utterly mistaken manner, or is it a easy repair?

I anticipated the whole lot to work, as I google’d extensively and appeared to be calling the API appropriately, however undecided what I must be doing in addition to

': End result'

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments