Open ashleydee1999 opened 1 year ago
I'm having the exact same issue and trying to access the image url the same way. Have you made any progress on this @ashleydee1999?
Hi @lmartinresnick, I never pursued it further due to no responses to my query. I'll reattempt it sometime this week and see how far I get
@ashleydee1999 I decided to use the first product's image for the entire collection for the meantime
@lmartinresnick yeah, that's my current implementation as well. This has been the one of the most difficult SDK's I've worked with, but hopefully they'll be a breakthrough on this particular issue
@ashleydee1999 You can type cast the reference using the correct Storefront type (you need to make sure to use the correct type, otherwise casting to an incorrect type will return a runtime exception.)
let metafieldURL = (filteredArr[0]?.reference as? Storefront.MediaImage).image?.url
Just make sure to safely unwrap your optionals and provide a default value in case of nil
Hi,
I am accessing my metafields successfully from the API. The issue I have is that one of the metafields is a MediaImage and I can't can't access the image URL as one of the properties.
My working Swift Query looks like this:
GraphQL working Query:
GraphiQL Response from the above query:
Trying to Access the Image URL of the MetaField
Printing the
metafieldURL
variable gives the following: