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

During 49: Caught a "sleeping guard" at the url check?

Forums > 100 Days of SwiftUI

UPDATE ON CONSOLE: It turns out I had to go to View > Debug > Activate Console to get the durned thing working again! (Why it stopped working in the first place is anybody's guess...)

The original question, if anyone is curious, is posted in the comments below:

struct Result: Codable {
    //these are some of the properties sent back from iTunes
    var trackId: Int
    var trackName: String
    var collectionName: String
}
struct Response: Codable {
    //our view model
    var results: [Result]
}

struct ContentView: View {
    @State private var results = [Result]()
    @State private var username = ""
    @State private var email = ""

    var body: some View {
        List(results, id: \.trackId) { item in
            VStack(alignment: .leading) {
                Text(item.trackName).font(.headline)
                Text(item.collectionName)
            }
        }
        .task {
            await loadData()
        }
//      DOES NOT SHOW UP IN CONSOLE, PART ONE:
        .onAppear(perform: {
            print("well, it appeared")
        })
//      Why not man?  (because the console was turned off!)
    }

    func loadData() async {

//      DOES NOT SHOW UP IN CONSOLE, PART TWO:
        print("inside loadData function")
//      Why not man?  (because the console was turned off!)

        guard let url = URL(string: "https:::://this url is soooo invalid") else {
            print("invalid URL")
            return
        }
        do {
            let (data, _) = try await URLSession.shared.data(from: url)
            if let decodedResponse = try? JSONDecoder().decode(Response.self, from: data) {
                results = decodedResponse.results
            }
        } catch {
            print("invalid data")
        }
    }
}

2      

Save 50% in my WWDC sale.

SAVE 50% To celebrate WWDC24, 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.