- Create a project in XCode with the default settings
- iOS > Application > Single View Application
- Language: Swift
- Under project General settings, add ReactKit to Linked Framework and Libraries
- + > Add Other... and choose /path/to/react-native/ReactKit/ReactKit.xcodeproj
- Now ReactKit would have been imported. Link it by choosing it from the list.
- + > lib.ReactKit.a
- Under project Build Settings,
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// RxKeyboard.swift | |
// RxTools | |
// | |
// Created by Roberto Frontado on 5/16/16. | |
// Copyright © 2016 Roberto Frontado. All rights reserved. | |
// | |
import RxSwift |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Repository {} | |
class ViewModel { | |
let repository: Repository | |
init(repository: Repository) { | |
self.repository = repository | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Repository {} | |
class ViewModel { | |
let repository: Repository | |
init() { | |
self.repository = Repository() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
@propertyWrapper | |
public struct Injected<Value> { | |
private var value: Value? | |
public var wrappedValue: Value { | |
get { | |
return value ?? SwiftDI.default.resolve() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Repository {} | |
class ViewModel { | |
@Injected var repository: Repository | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func registerDependencies() { | |
SwiftDI.configure { | |
$0.factory { Repository() } | |
} | |
} |
OlderNewer