Reputation: 3219
Having problems iterating through an optional enumerated type. Looking for general guidance if anyone has any and will post any code if needed.
It all stems from this
@Published var movielist: Movie?
but I'm really confused on how to handle this error.
Upvotes: 2
Views: 49
Reputation: 52525
(vm.movielist?.results ?? []).enumerated()
This way, if vm.movielist
is nil, then an empty collection gets used instead.
(this is the first "Fix" solution that Xcode gives, although sometimes it gets the syntax a little bit funny when it tries to fix things automatically that are in a chain like this)
Upvotes: 3