BLACK FRIDAY: 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() { }

    }

3      

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.

3      

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

3      

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

2      

Save 50% in my WWDC sale.

SAVE 50% All our books and bundles are half price for Black Friday, 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.