Skip to content

Instantly share code, notes, and snippets.

@marlonjames71
Created May 12, 2021 08:50
Show Gist options
  • Save marlonjames71/9624202447322c06ebd3e3999e3f8e5f to your computer and use it in GitHub Desktop.
Save marlonjames71/9624202447322c06ebd3e3999e3f8e5f to your computer and use it in GitHub Desktop.
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