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
final class MovieClient: CombineAPI { | |
// 1 | |
let session: URLSession | |
// 2 | |
init(configuration: URLSessionConfiguration) { | |
self.session = URLSession(configuration: configuration) | |
} | |
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
// 1 | |
protocol CombineAPI { | |
var session: URLSession { get } | |
func execute<T>(_ request: URLRequest, decodingType: T.Type, queue: DispatchQueue, retries: Int) -> AnyPublisher<T, Error> where T: Decodable | |
} | |
// 2 | |
extension CombineAPI { | |
func execute<T>(_ request: URLRequest, |
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
// 1 | |
@main | |
struct SwiftUIMoviesApp: App { | |
// 2 | |
@StateObject private var model = MoviesProvider() | |
// 3 | |
var body: some Scene { | |
WindowGroup { | |
// 4 |
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
// 1 | |
struct GenericList<Element, RowContent: View>: View where Element: Identifiable { | |
// 2 | |
private let items: [Element] | |
private let rowContent: (Element) -> RowContent | |
// 3 | |
public init(_ items: [Element], @ViewBuilder rowContent: @escaping (Element) -> RowContent) { | |
self.items = items |
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
import UIKit | |
class Vc: UIViewController { | |
var top: CGFloat? { 8 } | |
} | |
let viewController = Vc() | |
let a: CGFloat = 1.0 | |
let b: CGFloat = 2.0 | |
let result = (viewController as? Vc)?.top ?? a < b ? 10 : 15 |
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
class FrameTransitionAnimator: NSObject { | |
enum OverlayType { | |
case dim | |
case blur(style: UIBlurEffect.Style) | |
} | |
enum DimTransitionMode: Int { | |
case present, dismiss |
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
/// 1 | |
protocol DisplayModeUpdatable { | |
func displayModeWillChangeTo(_ displayMode: UISplitViewController.DisplayMode) | |
func displayModeDidChangeTo(_ displayMode: UISplitViewController.DisplayMode) | |
} | |
//// | |
@objc func togglePrefferDisplayModeExecutingCompletion(_ executing: Bool = true) { | |
UIView.animate(withDuration: 0.3, animations: { | |
self.preferredDisplayMode = self.displayMode == .allVisible ? .primaryHidden : .allVisible |
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
// In UserProfileViewController (the master) we need: | |
// 1 | |
protocol UserProfileFeedSelectionDelegate: AnyObject { | |
func postSelectedAt(_ indexPath: IndexPath) | |
} | |
// 2 | |
weak var delegate: UserProfileFeedSelectionDelegate? | |
// 3 | |
lazy private var contentDetailViewController: ContentDetailViewcontroller = { |
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
/// 1 convenience init. | |
convenience init(viewControllers: [UIViewController]) { | |
self.init() | |
/// 2 set master and detail, it takes an array of view controllers. | |
self.viewControllers = viewControllers | |
/// 3 preferredDisplayMode, it defines the display mode of the split view controller, | |
/// .allVisible will display both master and detail. | |
preferredDisplayMode = .allVisible | |
/// set the delegate to self to allow the `SplitViewController` handle the UISplitViewControllerDelegate methods. | |
super.delegate = self |