Created
October 15, 2018 11:34
-
-
Save vialyx/7a3b23e2f2d89896ffbb56d8eec92aa1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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