Skip to content

Instantly share code, notes, and snippets.

View ARamy23's full-sized avatar
👋
Hello, there!

Ahmed Ramy ARamy23

👋
Hello, there!
View GitHub Profile
import Foundation
import UIKit
enum WidgetType {
case search
case banner
}
class Interactor {
func buildWidgets() {
import Foundation
class Model {
let id: String
let link: String
let resizedLink: String
func toDao() -> ModelDAO {
let dao: ModelDAO = .init()
// properties injection
@ARamy23
ARamy23 / DatePresenter+Builder.swift
Created March 15, 2022 11:18
Simplifies Date Parsing Process and displaying
import Foundation
// MARK: - Date Format & Components
extension Date {
// MARK: - Helper types
enum Format: String, CaseIterable {
/// 15/03/2022, 11:02 AM
case ddMMyyyyHHmmA = "dd/MM/yyyy, HH:mm a"
/// "18/10/1993"
case ddMMyyyySlashed = "dd/MM/yyyy"
UserRouter.login(email: "ali@ali.gmail.com", password: "test12345").send(SwiftCairoUser.self) {[weak self] (response) in
switch response {
case .failure(let error):
// TODO: - Handle error as you want, printing isn't handling.
print(error)
protocol HandleAlamoResponse {
/// Handles request response, never called anywhere but APIRequestHandler
///
/// - Parameters:
/// - response: response from network request, for now alamofire Data response
/// - completion: completing processing the json response, and delivering it in the completion handler
func handleResponse<T: CodableInit>(_ response: DataResponse<Data>, completion: CallResponse<T>)
}
extension HandleAlamoResponse {
protocol CodableInit {
init(data: Data) throws
}
extension CodableInit where Self: Codable {
init(data: Data) throws {
/// Response completion handler beautified.
typealias CallResponse<T> = ((ServerResponse<T>) -> Void)?
/// API protocol, The alamofire wrapper
protocol APIRequestHandler: HandleAlamoResponse {
/// Calling network layer via (Alamofire), this implementation can be replaced anytime in one place which is the protocol itself, applied anywhere.
enum UserRequest: URLRequestBuilder {
// 1
case login(email: String, password: String)
case register(name: String, email: String, password: String, phone: String)
case userInfo
// MARK: - Path
internal var path: ServerPaths {
// 2
enum UserRequest: URLRequestBuilder {
case login(email: String, password: String)
case register(name: String, email: String, password: String, phone: String)
case userInfo
// MARK: - Path
internal var path: ServerPaths {
switch self {
case .login:
enum ServerPaths: String {
case login
case register
case phoneActivation = "phone_activation"
case resendPhoneActivation = "resend_phone_activation_code"
case resendEmailLink = "send_reset_link_email"
case resetPassword = "reset_password"
case userInfo = "get_account_info"
case updateInfo = "update_account_info"
case userBalance = "get_user_internal_balance"