Created
May 12, 2021 08:50
-
-
Save marlonjames71/9624202447322c06ebd3e3999e3f8e5f to your computer and use it in GitHub Desktop.
This file contains 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
private func mediaViewControllerAtIndex(_ index: Int) -> MediaViewController? { | |
// returns nil if the index is out of bounds, this way the app won't crash. | |
// You can also put a print statement before you return. | |
guard (0...mediaItems.count).contains(index) else { return nil } | |
let item = mediaItems[index] | |
switch item.mediaType { | |
case .video: | |
return VideoViewController(mediaItem: item) | |
case .photo: | |
return PhotoViewController(mediaItem: item) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment