Moltin doesn't get response on Xcode


#1

I’m just starting, I added a product to the store, connect client id, when I run this, I get nothing

moltin.product.all { (result) in
switch result {
case .success(let response):
print(“Got products: (response.data)”)

            print(result)
        case .failure(let error):
            print("Got failure: \(error)")
        }
    }

I get “Got products” message but doesn’t print them. any ideas


#2

Hey Yasser,

Giving this a try right now, at first glance though it looks like you need to escape the string

print("Got products: \(response.data)")

I would also recommend,
https://docs.moltin.com/catalog/products/get-all-products

let moltin = Moltin(withClientID: "<your client ID>")
​
self.moltin.product.include([.mainImage]).all { (result: Result<PaginatedResponse<[moltin.Product]>>) in
   switch result {
       case .success(let response):
            DispatchQueue.main.async {
               //set it to an array you can use in the class
                self.products = response.data ?? []
                print("Got products: \(response.data)")
            }
        case .failure(let error):
            print("Products error", error)
        }
    }
}

Let me know if you are able to get that to work. We have a bunch of iOS guides and boilerplate apps, happy to help.

-George


#3

Thanks for the reply, I only get

[moltin.Product, moltin.Product]
because I have 2 products, how can I get them as actual data


#4

Oh, I just got it by using
print(response.first.name)
instead of
print(response)

thanks :slight_smile:

one more question, can I connect Firebase user login and out to it or do you have user management as well ?

thanks again :slight_smile:


#5

yes you could for sure do that. I would recommend making the call to firebase and in the response making the call to moltin to create the user. I can stub out an example for you.