Skip to content

Instantly share code, notes, and snippets.

@vialyx
Created October 15, 2018 11:34
Show Gist options
  • Save vialyx/7a3b23e2f2d89896ffbb56d8eec92aa1 to your computer and use it in GitHub Desktop.
Save vialyx/7a3b23e2f2d89896ffbb56d8eec92aa1 to your computer and use it in GitHub Desktop.
let mediaSet: [Media] = [Video(url: "http://[email protected]", thumb: "http://[email protected]"),
Video(url: "http://[email protected]", thumb: "http://[email protected]"),
Media(url: "http://[email protected]")]
for media in mediaSet {
// We don't sure about casting result
if let video = media as? Video {
print("Video: \(video)")
}
switch media {
case is Video:
// We are sure about casting result, because we checked it before
let video = media as! Video
print("Video: \(video)")
default:
break
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment