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 UserDefaults { | |
subscript<T>(key: String) -> T? { | |
get { | |
return value(forKey: key) as? T | |
} | |
set { | |
set(newValue, forKey: key) | |
} | |
} | |
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 | |
let json = """ | |
{ | |
"businesses": [ | |
{ | |
"id": "joes-pizza-new-york-4", | |
"name": "Joe's Pizza", | |
"image_url": "https://s3-media2.fl.yelpcdn.com/bphoto/FhbFkrh_3TrAOZvoWTyOJA/o.jpg", | |
"is_closed": false, |
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
final class ProfileRouter: Router<ProfileViewController> { | |
typealias Routes = Closable | |
} | |
final class ProfileViewController: UIViewController { | |
private let router: ProfileRouter.Routes | |
init(router: ProfileRouter.Routes) { | |
self.router = router |
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
protocol ProfileRoute { | |
var profileTransition: Transition { get } | |
func openProfile(for user: User) | |
} | |
extension ProfileRoute where Self: RouterProtocol { | |
var profileTransition: Transition { | |
return ModalTransition() | |
} |
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
final class FriendsRouter: Router<FriendsViewController>, FriendsRouter.Routes { | |
typealias Routes = ProfileRoute & /* other routes */ | |
} | |
final class FriendsViewController: UIViewController { | |
private let router: FriendsRouter.Routes | |
init(router: FriendsRouter.Routes) { | |
self.router = router |
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
protocol Closable: class { | |
func close() | |
} | |
protocol RouterProtocol: class { | |
associatedtype V: UIViewController | |
weak var viewController: V? { get } | |
func open(_ viewController: UIViewController, transition: Transition) | |
} |
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
protocol Animator: UIViewControllerAnimatedTransitioning { | |
var isPresenting: Bool { get set } | |
} |
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 PushTransition: NSObject { | |
var animator: Animator? | |
weak var viewController: UIViewController? | |
init(animator: Animator? = nil) { | |
self.animator = animator | |
} | |
} | |
extension PushTransition: Transition {} |
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 ModalTransition: NSObject { | |
var animator: Animator? | |
weak var viewController: UIViewController? | |
init(animator: Animator? = nil) { | |
self.animator = animator | |
} | |
} | |
extension ModalTransition: Transition {} |
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
protocol Transition: class { | |
weak var viewController: UIViewController? { get set } | |
func open(_ viewController: UIViewController) | |
func close(_ viewController: UIViewController) | |
} |