Skip to content

Instantly share code, notes, and snippets.

View NonConformingModule.swift
let nonCompliantModule = NonConformingModule()
nonCompliantModule.login(username: "myUsername",
password: "myPassword",
completion: { (bearerToken, error) in
print(String(describing: bearerToken))
})
class NonConformingModule {
View URLRouter.swift
@objc class URLRouter: URLProtocol, URLSessionDataDelegate, URLSessionTaskDelegate {
// TODO: This is synchronisyng only write access, which might be inadequate in many cases
// Need to be replaced with proper full generic implementation of synchronized collection
private (set) var moduleQueue = DispatchQueue(label: "com.tandem.module.queue")
// MARK: URLProtocol methods overriding
override class func canInit(with task: URLSessionTask) -> Bool {
View NetworkService.swift
enum HTTPMethod: String {
case GET
case POST
}
class NetworkService {
func get(scheme: String? = nil,
host: String,
View PaymentsModuleRouter.swift
class PaymentsModuleRouter: ModuleRouter {
lazy var interactor = PaymentInteractor()
internal var route: String
required init(route: String) {
self.route = route
}
View LoginInteractor.swift
class LoginInteractor {
func getPaymentToken(parameters: ModuleParameters?,
completion: @escaping (String?, HTTPURLResponse?, Error?) -> Void) {
let service = MockLoginNetworkService()
guard let parameters = parameters,
let username = parameters[LoginModuleParameters.username.rawValue],
let password = parameters[LoginModuleParameters.password.rawValue] else {
return
View LoginModuleRouter.swift
/**
This interface defines few simple steps:
- store the module route, so it can be accessed many times
- route the request sent to the module with parameters to desired functionality which is encapsulated in the module
*/
protocol ModuleRouter {
var route: String { get set }
init(route: String)
View ApplicationServices.swift
class ApplicationServices {
// ApplicationServices is a singleton, because it makes it easier to be accessed from anywhere to access its functions/services
static let shared = ApplicationServices()
let appRouter = ApplicationRouter()
func pay(amount: Double,
username: String,
password: String,
completion: @escaping (() -> Void)) {
View LoginAndPaymentModule.swift
class LoginModule: ModuleType {
var route: String = {
return "login"
}()
var paths: [String] = {
return ["/login",
"/logout",
"/payment-token"]
@poksi592
poksi592 / Module.swift
Created May 14, 2018
Module infrastructure
View Module.swift
public typealias ModuleParameters = [String: String]
/**
Application module represents a group off all the classes that implement a certain functionality of the module, like:
- Storyboard
- View Controllers
- Views, specific to the module
- Presenters, View Models and other Client architecture classes
- ...
View ApplicationRouter.swift
public typealias ModuleCallback = ([String: Any]?, Data?, URLResponse?, Error?) -> Void
/**
Protocol defines application router, which function is
- register application modules
- access/open the modules
- provide the callback, result of the access
*/
protocol ApplicationRouterType: class {
You can’t perform that action at this time.