Skip to content

Instantly share code, notes, and snippets.

View AlexApostolSource's full-sized avatar

Alex Apostol AlexApostolSource

View GitHub Profile
/// Print Current simulator folder
// Catch a Breakpoint somewhere. (or Pause program execution (tap on pause in debug area)
// Enter po NSHomeDirectory() in console window
po NSHomeDirectory() ->
//Users/usernam/Library/Developer/CoreSimulator/Devices/
//4734F8C7-B90F-4566-8E89-5060505E387F/data/Containers/Data/Application/395818BB-6D0F-499F-AAFE-068A783D9753
@AlexApostolSource
AlexApostolSource / Debouncer.swift
Created October 9, 2025 15:28
Debouncer Aync Await
//
// Debouncer.swift
// DesignPatternsShowCase
//
// Created by Alex.personal on 9/10/25.
//
import Foundation
public typealias DebounceAction = @Sendable () async throws -> Void
@AlexApostolSource
AlexApostolSource / SharedMutableState.swift
Created October 4, 2024 19:36
SharedMutableState Approach
public final actor SharedMutableState {
private static let defaultPath = "www.google.com"
public static var basePath: String {
completion?() ?? defaultPath
}
private static var completion: (() -> String)?
static func config(basePath: String) {
completion = {
import UIKit
class LoginViewController: UIViewController {
var presenter: LoginViewControllerPresenterProtocol
let model: LoginViewControllerModel
lazy var titleLabel: UIView = {
let view = UIView(frame: .zero)
@AlexApostolSource
AlexApostolSource / LoginViewPresenter
Created February 25, 2021 09:43
Login View Presenter
import Foundation
class LoginViewPresenter: LoginViewControllerPresenterProtocol {
weak var view: LoginViewProtocol?
var dataManager: LoginDataManagerProtocol
var coordinatorOutPut: (LoginViewOutput) -> Void
init(dataManager: LoginDataManagerProtocol,coordinatorOutput:@escaping(LoginViewOutput)->Void) {
self.dataManager = dataManager
@AlexApostolSource
AlexApostolSource / UserEndPoint.swift
Created February 25, 2021 08:47
Request Builder
enum UserEndPoint {
case userList
}
extension UserEndPoint: RequestBuilder {
var urlRequest: URLRequest {
switch self {
case .userList:
guard let url = URL(string: "https://jsonplaceholder.typicode.com/users")
extension URLSession {
func get<T:Codable>(_ builder: RequestBuilder, type: T.Type, callback: @escaping(Result<T?,ApiError>) -> Void) {
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
let dataTask = self.dataTask(with: builder.urlRequest) { data, response, error in
if let error = error {
@AlexApostolSource
AlexApostolSource / LoginDataManager.swift
Last active February 25, 2021 09:53
LoginDataManager
import Foundation
class LoginDataManager: LoginDataManagerProtocol {
func getUser(callback: @escaping (Result<[User], ApiError>) -> Void) {
URLSession.shared.get(UserEndPoint.userList, type: [User].self) { (result) in
switch result {
case .success(let users):
if let users = users {
callback(.success(users))
class LoginViewBuilder: Builder {
var coordinatorOutput: (LoginViewOutput) -> Void
init( coordinatorOtput:@escaping(LoginViewOutput)-> Void) {
self.coordinatorOutput = coordinatorOtput
}
func build() -> UIViewController {
let dataManager = LoginDataManager()
let presenter = LoginViewPresenter(dataManager: dataManager, coordinatorOutput: coordinatorOutput)
import UIKit
public class AppCoordinator: Coordinator {
public enum AppCoordinatorState {
case inital
case willShowLoginFlow
case didShowLoginFlow
case willShowTasksFlow(userId:Int?)
}