What is the best way to determine if an array of enum types contains a specific enum type, the kicker is the enum cases have associated types
for example, with the following data structure, how would I get the first video
let sections = [OnDemandSectionViewModel]
public struct OnDemandSectionViewModel: AutoEquatable {
public let sectionStyle: SectionHeaderStyle
public let sectionItems: [OnDemandItemType]
public let sectionType: SectionType
}
public enum OnDemandItemType: AutoEquatable {
case video(VideoViewModel)
case button(ButtonViewModel)
case game(GameViewModel)
case collectionGroup(CollectionGroupViewModel)
case clip(ClipViewModel)
}
I'm trying to find the first video, currently, I'm doing the following, but was curious if there is a better way
for section in sections {
for item in section.sectionItems {
switch item {
case .video(let video):
print("This is the first video \(video)")
return
default: break
}
}