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

Day 52 Challenge 3 - strange error

Forums > 100 Days of SwiftUI

I'm getting a very strange error every time I try to place the order. This is what the console says :

nw_protocol_get_quic_image_block_invoke dlopen libquic failed

I've tried comparing my code to what others have posted online but i don't see what I'm doing wrong...

Here's my checkout view:


import SwiftUI

struct CheckoutView: View {

    func placeOrder(){
        guard let encoded = try? JSONEncoder().encode(orderC.orderS) else {
            print("Failed to encode order")
            return
        }

        let url = URL(string: "https://reqres.in/api/cupcakes")!
        var request = URLRequest(url: url)
        request.setValue("application/json", forHTTPHeaderField: "Content-Type")
        request.httpMethod = "POST"
        request.httpBody = encoded

        URLSession.shared.dataTask(with: request){ data, response, error in

            guard let data = data else{
                print("No data in response: \(error?.localizedDescription ?? "Unknown Error").")
                let message: String = error?.localizedDescription ?? "Unknown error occured"
                self.errorMessage = message
                self.showingError = true
                return
            }

            if let decodedOrder = try? JSONDecoder().decode(OrderS.self, from: data){
                self.confirmationMessage = "Your order for \(decodedOrder.quantity) x \(OrderS.types[decodedOrder.type].lowercased()) cupcakes is on its way!"
                self.showingConf = true
            } else {
                print("Invalid response from server")
            }

        }.resume()

    }

    @State private var confirmationMessage = ""
    @State private var showingConf = false

    @State private var errorMessage = ""
    @State private var showingError = false

    @ObservedObject var orderC: OrderC
    var body: some View {

        GeometryReader{ geo in

            ScrollView{
                VStack{
                    Image("cupcakes")
                        .resizable()
                        .scaledToFit()
                        .frame(width: geo.size.width)

                    Text("Your order total is: $\(orderC.orderS.cost, specifier: "%.2f")")
                        .font(.title)

                    Button("Place order"){
                        self.placeOrder()
                    }.padding()
                }
            }

        }.navigationBarTitle("Checkout", displayMode: .inline)
        .alert(isPresented: $showingConf){
            Alert(title: Text("Thank you!"), message: Text(confirmationMessage), dismissButton: .default(Text("OK")))
        }
        .alert(isPresented: $showingError){
            Alert(title: Text("Error"), message: Text(errorMessage), dismissButton: .default(Text("OK")))
        }

    }
}

struct CheckoutView_Previews: PreviewProvider {
    static var previews: some View {
        CheckoutView(orderC: OrderC())
    }
}

and here's my Order class and struct:


class OrderC: ObservableObject{

    @Published var orderS = OrderS()

}

struct OrderS: Codable {

        static var types = ["Vanilla", "Chocolate", "Strawberry", "Rainbow"]

        var type = 0
        var quantity = 3
        var specialRequestEnabled = false{
            didSet{
                if specialRequestEnabled == false{
                    self.extraFrosting = false
                    self.addSprinkles = false
                }
            }
        }

        var extraFrosting = false
        var addSprinkles = false

        var name = ""
        var streetAddress = ""
        var city = ""
        var zip = ""

        var hasValidAddress: Bool {

            let nameed = name.trimmingCharacters(in: .whitespacesAndNewlines)
            let added = streetAddress.trimmingCharacters(in: .whitespacesAndNewlines)
            let cityed = city.trimmingCharacters(in: .whitespacesAndNewlines)
            let ziped = zip.trimmingCharacters(in: .whitespacesAndNewlines)

            if nameed.isEmpty || added.isEmpty || cityed.isEmpty || ziped.isEmpty {
                return false
            }
            return true
        }

        var cost: Double{

            var cost = Double(quantity) * 2

            cost += (Double(type) / 2)

            if extraFrosting{
                cost += Double(quantity)
            }

            if addSprinkles{
                cost += (Double(quantity) / 2)
            }

            return cost
        }

    init() { }

    }

1      

There is another related question (for the same error) - here

Maybe that will help.

Seems to be, from what I read, that for the moment it is possible to ignore the error.

1      

Thank you! I can't seem to get the app to run properly though... Nothing happens when I click the 'place order' button, and then this error shows up in the console. I'n not sure what part of my code is wrong...

1      

@7elysium, did you solve this Challenge 3? Anybody chime in here? Would really appreciate some help. I also made a post about Project 10 Challenge 3. Thanks.

   

Hacking with Swift is sponsored by Emerge

SPONSORED Optimize your app’s startup time, binary size, and overall performance using Emerge’s advanced app optimization and monitoring tools. Reliably measure app size, speed up your app's startup time with Emerge's Launch Booster, and much more. Emerge is actively used by many of the top mobile development teams in the world.

Find out more

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

Reply to this topic…

You need to create an account or log in to reply.

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.