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 Foundation | |
class BasicGHUsersAPI: GitHubUsersAPI { | |
var service: BaseService<String>? | |
func getLocationFor(_ user: String, completion: @escaping (String) -> ()) { | |
let apiBuilder = GitHubAPIBuilder<String>() | |
service = apiBuilder.buildAPI(for: GETUsersCityRequest(user), decodingProcessor: StringDecodingProcessor(), nestedModelGetter: GitHubNestedModelGetter.usersLocation) | |
_ = service?.sendRequest()?.onSucces({ (city) in |
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 ViewController: UIViewController { | |
let ghReposAPI: ReposGettable = ReposAPI() | |
let ghUserAPI: GitHubUsersAPI = BasicGHUsersAPI() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
ghReposAPI.getRepos { (repos) in |
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 Foundation | |
struct GETUsersLocationRequest: HTTPGETRequest { | |
var path: String = "https://api.github.com/users/" | |
var parameters: JSON? | |
var headerFields: [String: String]? | |
init(_ userName: String) { | |
path += userName | |
} |
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 Foundation | |
enum GitHubNestedModelGetter: String, NestedModelGetter { | |
case usersLocation = "location" | |
var keyPath: String { | |
return self.rawValue | |
} | |
} |
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 | |
struct AlertModel { | |
struct ActionModel { | |
var title: String? | |
var style: UIAlertAction.Style | |
var handler: ((UIAlertAction) -> ())? | |
} | |
var actionModels = [ActionModel]() |
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 AlertBuilder { | |
static func buildAlertController(for model: AlertModel) -> UIAlertController { | |
let controller = UIAlertController(title: model.title, message: model.message, preferredStyle: model.prefferedStyle) | |
model.actionModels.forEach({ controller.addAction(UIAlertAction(title: $0.title, style: $0.style, handler: $0.handler)) }) | |
return controller | |
} |
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 | |
import Bond | |
protocol AlertPresentableView { | |
associatedtype ModelType: AlertPresentableViewModel | |
var model: ModelType { get set } | |
} | |
extension AlertPresentableView where Self: UIViewController { |
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 Bond | |
protocol AlertPresentableViewModel { | |
var alertModel: Observable<AlertModel?> { get set } | |
} |
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 ViewController: UIViewController, AlertPresentableView { | |
var model = ViewModel() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
bindToAlerts() | |
model.setup() |
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 Foundation | |
import Bond | |
class ViewModel: AlertPresentableViewModel { | |
var alertModel = Observable<AlertModel?>(nil) | |
func setup() { | |
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { | |
self.alertModel.value = AlertModel(actionModels: [AlertModel.ActionModel.init(title: "OK", style: .default, handler: nil)], title: "Alert example", message: "That's our easy alert.", prefferedStyle: .alert) | |
} |