UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

"Fetch error" in HWS SwiftUI edition in Chapter 10 - Cupcake Corner

Forums > Books

When I run the code to retreive the Taylor Swift song list in the initial part of the chapter what I see in the console is Fetch error: Unknown error and no data is retrieved!

I have checked the code over and over again and I've checked the URL. All is correct as far as I can tell, but just the error.

Have others had any issues? Does yours work?

And yes, .resume() is in the code for the URLSession!

Any help gratefully appreciated.

3      

Hey, would you mind uploading your code to Github and posting the link so we can check it out? Thanks

3      

Thanks very much for your offer. I've never loaded anything onto Github so I'll have to work out how to do it first - a useful excersise in itself!

I continued with the rest of the chapter and coded the rest of it which makes the URL request and displays the returned JSON and that all just works fine.

I will see about uploading the code - hold on to your hat. :-)

3      

I received this error message as well. Turns out I had typed "trackID" instead of "trackId" in the code. If you paste the URL in Safari, if the URL is correct you'll get a downloaded file.

You can add a print in the URLSession call to see if you're getting data from the request as well like this:

if let data = data {
            print(data) // will print nnnnn bytes if data received

Steve

3      

Always double-check the spelling of the keys. Every key you declare must exactly match a key in the data. Even the smallest misspelling will cause a failure without any explanation.

I check the keys by retrieving the url with a browser and comparing my keys to the keys in the text file that is downloaded.

3      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.