NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

"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      

Hacking with Swift is sponsored by Play

SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!

Click to learn more about Play!

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.