Ad

Shopify IOS SDK - Issue Converting BuyProductVariant To BuyProduct

- 1 answer

I am having an issue converting a BuyProductVariant to BuyProduct, as from BuyCart i am getting the array of all the Variants which are added in that cart with the following code

NSArray *arr = cart.lineItems;

Now as per my understanding, this array contains all the Variants which are added in the Cart.

After that I am getting those object in BuyProductVariant

for (int j=0; j<arr.count; j++) {
     BUYProductVariant *variant = arr[j];
     //As the product is defined in BuyProductVariant class
     BUYProduct *product = variant.product;
     //But when the above line executes the app crashes, below is the description
}

exception: -[__NSDictionaryM product]: unrecognized selector sent to instance 0x7fd3286d3c50

Now, in the above code, where am i doing the wrong, any help would be very helpful to me.

Thanks

Ad

Answer

the BUYCart.lineItems array does not contain BUYProductVariant object. It contains BUYCartLineItem objects. You can retrieve your BUYProductVariant from it.

for (BUYCartLineItem* line in cart.lineItems) {

    BUYProductVariant* productVariant = line.variant;
}
Ad
source: stackoverflow.com
Ad