Skip to content

Instantly share code, notes, and snippets.

View IsaAliev's full-sized avatar

Isa Aliev IsaAliev

  • Moscow, Russia
View GitHub Profile
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
import UIKit
class ViewController: UIViewController {
let ghReposAPI: ReposGettable = ReposAPI()
let ghUserAPI: GitHubUsersAPI = BasicGHUsersAPI()
override func viewDidLoad() {
super.viewDidLoad()
ghReposAPI.getRepos { (repos) in
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
}
import Foundation
enum GitHubNestedModelGetter: String, NestedModelGetter {
case usersLocation = "location"
var keyPath: String {
return self.rawValue
}
}
import UIKit
struct AlertModel {
struct ActionModel {
var title: String?
var style: UIAlertAction.Style
var handler: ((UIAlertAction) -> ())?
}
var actionModels = [ActionModel]()
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
}
import UIKit
import Bond
protocol AlertPresentableView {
associatedtype ModelType: AlertPresentableViewModel
var model: ModelType { get set }
}
extension AlertPresentableView where Self: UIViewController {
import Bond
protocol AlertPresentableViewModel {
var alertModel: Observable<AlertModel?> { get set }
}
import UIKit
class ViewController: UIViewController, AlertPresentableView {
var model = ViewModel()
override func viewDidLoad() {
super.viewDidLoad()
bindToAlerts()
model.setup()
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)
}