WWDC23 SALE: Save 50% on all my Swift books and bundles! >>

"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.

1      

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

1      

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. :-)

1      

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

1      

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.

1      

Save 50% in my WWDC23 sale.

SAVE 50% To celebrate WWDC23, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

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.