I am filling in a UICollectionView with results from a query. Sometimes, the resulting stories don't have images. I would like to skip those objects entirely.
How can I skip over results from a JSON query that don't have any image present? It looks like I should use flatMap, but can't get it going.
Here is the code I'm using:
<a href="#">Test</a>
答案 0 :(得分:1)
There are two ways to solve this:
Don't append the article if the Value Objects
nil
Append everything, but then filter the items with image only:
let hasImageArticles = articles.filter({ $0.imageURL != nil })