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
// For one dimensional array | |
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { | |
let item = mediaItems[indexPath.item] | |
let pagedMediaViewController = PagedMediaController(mediaItem: item, currentIndex: indexPath.item) | |
pagedMediaViewController.modalPresentationStyle = .overFullScreen | |
present(pagedMediaViewController, animated: true) | |
} | |
// In case you're dealing with a two dimensional array like I was dealing with since the collection view's items | |
// had sections |
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
class MediaViewController: UIViewController { | |
let mediaItem: MediaItem | |
init(mediaItem: MediaItem) { | |
self.mediaItem = mediaItem | |
} | |
required init(coder: NSCoder) { | |
fatalError("Use init(mediaItem: MediaItem)") | |
} |
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
class PagedMediaViewController: UIPageViewController { | |
// MARK: - Properties | |
private var mediaItems: [MediaItem] | |
private var currentIndex: Int | |
// MARK: - Init | |
init(mediaItems: [MediaItem], currentIndex: Int) { | |
self.mediaItems = mediaItems | |
self.currentIndex = currentIndex |
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
struct MediaItem { | |
let id: UUID | |
let mediaType: MediaType | |
let title: String? | |
let mediaUrl: URL? | |
} | |
enum MediaType { case video, photo } |
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
// For one dimensional array | |
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { | |
let item = mediaItems[indexPath.item] | |
let pagedMediaViewController = PagedMediaController(mediaItem: item, currentIndex: indexPath.item) | |
pagedMediaViewController.modalPresentationStyle = .overFullScreen | |
present(pagedMediaViewController, animated: true) | |
} | |
// In case you're dealing with a two dimensional array like I was dealing with since the collection view | |
// had sections |
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
extension UIView { | |
/// Applies rounded corners with masking to specific corners and with corner curve option. | |
func roundCorners(cornerRadius: CGFloat, roundedStyle: CALayerCornerCurve, corners: CACornerMask) { | |
layer.cornerRadius = cornerRadius | |
layer.cornerCurve = roundedStyle | |
layer.maskedCorners = corners | |
} | |
} |
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
struct MyViewControllerClass_Previews: PreviewProvider { | |
static var previews: some View { | |
UIViewControllerPreview { | |
return MyViewControllerClass() | |
} | |
.previewDevice("iPhone SE (2nd generation)") | |
} | |
} | |
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
// This was originally done in Playgrounds | |
// You can plop this in Playgrounds and it should work. | |
import UIKit | |
let title = "The best camping trip of the year with the best friends" | |
func checkForValidQueryString(_ string: String) -> Bool { | |
guard | |
!string.isEmpty, |
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
extension Color { | |
static let bg = Color("mainBG") | |
static let secondaryBG = Color("secondaryBG") | |
static let greyText = Color("greyText") | |
} |
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
import Foundation | |
protocol NextObject: AnyObject, Hashable { | |
func isEqual(_ object: Any?) -> Bool | |
var hash: Int { get } | |
var superclass: AnyClass? { get } | |
func `self`() -> Self |