Skip to content

Instantly share code, notes, and snippets.

View robertofrontado's full-sized avatar
🐶
Working from home

Roberto Frontado robertofrontado

🐶
Working from home
View GitHub Profile
@robertofrontado
robertofrontado / RxMoyaProvider.swift
Created March 10, 2016 15:41
Returning Observable from request on a background thread
import Foundation
import RxSwift
/// Subclass of MoyaProvider that returns Observable instances when requests are made. Much better than using completion closures.
public class RxMoyaProvider<Target where Target: TargetType>: MoyaProvider<Target> {
/// Initializes a reactive provider.
override public init(endpointClosure: EndpointClosure = MoyaProvider.DefaultEndpointMapping,
requestClosure: RequestClosure = MoyaProvider.DefaultRequestMapping,
stubClosure: StubClosure = MoyaProvider.NeverStub,
manager: Manager = RxMoyaProvider<Target>.DefaultAlamofireManager(),
@robertofrontado
robertofrontado / RxKeyboard
Created May 17, 2016 17:26
Useful Rx tool to works with the Keyboard states in iOS
//
// RxKeyboard.swift
// RxTools
//
// Created by Roberto Frontado on 5/16/16.
// Copyright © 2016 Roberto Frontado. All rights reserved.
//
import RxSwift
@robertofrontado
robertofrontado / README.md
Created July 2, 2017 16:46 — forked from boopathi/README.md
Creating a Swift-ReactNative project

Settings

  1. Create a project in XCode with the default settings
    • iOS > Application > Single View Application
    • Language: Swift
  2. Under project General settings, add ReactKit to Linked Framework and Libraries
    • + > Add Other... and choose /path/to/react-native/ReactKit/ReactKit.xcodeproj
  3. Now ReactKit would have been imported. Link it by choosing it from the list.
    • + > lib.ReactKit.a
  4. Under project Build Settings,
@robertofrontado
robertofrontado / ClassWithDependencyInjection.swift
Last active April 13, 2020 15:02
DependencyInjectionExample
class Repository {}
class ViewModel {
let repository: Repository
init(repository: Repository) {
self.repository = repository
}
}
@robertofrontado
robertofrontado / ClassWithoutDependencyInjection.swift
Last active April 13, 2020 15:02
ClassWithoutDependencyInjection
class Repository {}
class ViewModel {
let repository: Repository
init() {
self.repository = Repository()
}
}
import Foundation
public class SwiftDI {
public static let `default` = SwiftDI()
private var dependencies = [String: Resolver]()
public static func configure(container: SwiftDI = .default, _ config: (SwiftDI) -> Void) {
config(container)
@robertofrontado
robertofrontado / Resolver.swift
Created April 1, 2020 21:36
SwiftDI - Resolver
internal enum Resolver {
case single(object: Any)
case factory(block: () -> Any)
func resolve() -> Any {
switch self {
case .single(let object): return object
case .factory(let block): return block()
}
}
@robertofrontado
robertofrontado / Injected.swift
Last active April 13, 2020 15:05
SwiftDI - Injected With Caching
import Foundation
@propertyWrapper
public struct Injected<Value> {
private var value: Value?
public var wrappedValue: Value {
get {
return value ?? SwiftDI.default.resolve()
@robertofrontado
robertofrontado / ClassWithSwiftDI.swift
Last active April 13, 2020 15:03
SwiftDI - Example
class Repository {}
class ViewModel {
@Injected var repository: Repository
}
@robertofrontado
robertofrontado / SwiftDIRegistration.swift
Last active April 13, 2020 15:03
SwiftDI - Registration
func registerDependencies() {
SwiftDI.configure {
$0.factory { Repository() }
}
}