Skip to content

Implement Example in Combine #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: combine
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 26 additions & 35 deletions XCoordinator-Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
9B0A753A2316C1810092CA3A /* XCoordinatorRx in Frameworks */ = {isa = PBXBuildFile; productRef = 9B0A75392316C1810092CA3A /* XCoordinatorRx */; };
2E7649E8240D9A3800F08477 /* CombineCocoa in Frameworks */ = {isa = PBXBuildFile; productRef = 2E7649E7240D9A3800F08477 /* CombineCocoa */; };
2E7649EB240D9CA800F08477 /* XCoordinatorCombine in Frameworks */ = {isa = PBXBuildFile; productRef = 2E7649EA240D9CA800F08477 /* XCoordinatorCombine */; };
2E7649ED240D9CA800F08477 /* XCoordinator in Frameworks */ = {isa = PBXBuildFile; productRef = 2E7649EC240D9CA800F08477 /* XCoordinator */; };
9B56575B2315FA7E00F4F4F7 /* XCoordinator_ExampleUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B56575A2315FA7E00F4F4F7 /* XCoordinator_ExampleUITests.swift */; };
9B5657A72315FB3500F4F4F7 /* AppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B5657692315FB3500F4F4F7 /* AppCoordinator.swift */; };
9B5657A82315FB3500F4F4F7 /* UserListCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B56576A2315FB3500F4F4F7 /* UserListCoordinator.swift */; };
Expand Down Expand Up @@ -56,8 +58,6 @@
9B5657D32315FB3500F4F4F7 /* Presentable+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B5657A32315FB3500F4F4F7 /* Presentable+Rx.swift */; };
9B5657D42315FB3500F4F4F7 /* TransitionAnimation+Defaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B5657A42315FB3500F4F4F7 /* TransitionAnimation+Defaults.swift */; };
9B5657D62315FB3500F4F4F7 /* CGAffineTransform+InPlace.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B5657A62315FB3500F4F4F7 /* CGAffineTransform+InPlace.swift */; };
9B5657D92315FB9700F4F4F7 /* Action in Frameworks */ = {isa = PBXBuildFile; productRef = 9B5657D82315FB9700F4F4F7 /* Action */; };
9B5657DC2315FC1000F4F4F7 /* RxCocoa in Frameworks */ = {isa = PBXBuildFile; productRef = 9B5657DB2315FC1000F4F4F7 /* RxCocoa */; };
9BD3EBF42330CE46005861BF /* Transitions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BD3EBF32330CE46005861BF /* Transitions.swift */; };
9BD3EBFD2330D84F005861BF /* XCText+Extras.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BD3EBF62330D84E005861BF /* XCText+Extras.swift */; };
9BD3EBFE2330D84F005861BF /* XCTestManifests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BD3EBF72330D84F005861BF /* XCTestManifests.swift */; };
Expand Down Expand Up @@ -166,9 +166,9 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9B0A753A2316C1810092CA3A /* XCoordinatorRx in Frameworks */,
9B5657DC2315FC1000F4F4F7 /* RxCocoa in Frameworks */,
9B5657D92315FB9700F4F4F7 /* Action in Frameworks */,
2E7649EB240D9CA800F08477 /* XCoordinatorCombine in Frameworks */,
2E7649ED240D9CA800F08477 /* XCoordinator in Frameworks */,
2E7649E8240D9A3800F08477 /* CombineCocoa in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -448,9 +448,9 @@
);
name = "XCoordinator-Example";
packageProductDependencies = (
9B5657D82315FB9700F4F4F7 /* Action */,
9B5657DB2315FC1000F4F4F7 /* RxCocoa */,
9B0A75392316C1810092CA3A /* XCoordinatorRx */,
2E7649E7240D9A3800F08477 /* CombineCocoa */,
2E7649EA240D9CA800F08477 /* XCoordinatorCombine */,
2E7649EC240D9CA800F08477 /* XCoordinator */,
);
productName = "XCoordinator-Example";
productReference = 9B5657352315FA7B00F4F4F7 /* XCoordinator-Example.app */;
Expand Down Expand Up @@ -525,9 +525,8 @@
);
mainGroup = 9B56572C2315FA7B00F4F4F7;
packageReferences = (
9B5657D72315FB9700F4F4F7 /* XCRemoteSwiftPackageReference "Action" */,
9B5657DA2315FC1000F4F4F7 /* XCRemoteSwiftPackageReference "RxSwift" */,
9B5657DD2315FC5C00F4F4F7 /* XCRemoteSwiftPackageReference "XCoordinator" */,
2E7649E6240D9A3800F08477 /* XCRemoteSwiftPackageReference "CombineCocoa" */,
2E7649E9240D9CA800F08477 /* XCRemoteSwiftPackageReference "XCoordinator" */,
);
productRefGroup = 9B5657362315FA7B00F4F4F7 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -948,47 +947,39 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
9B5657D72315FB9700F4F4F7 /* XCRemoteSwiftPackageReference "Action" */ = {
2E7649E6240D9A3800F08477 /* XCRemoteSwiftPackageReference "CombineCocoa" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/RxSwiftCommunity/Action.git";
repositoryURL = "git@github.com:CombineCommunity/CombineCocoa.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 4.0.1;
minimumVersion = 0.1.0;
};
};
9B5657DA2315FC1000F4F4F7 /* XCRemoteSwiftPackageReference "RxSwift" */ = {
2E7649E9240D9CA800F08477 /* XCRemoteSwiftPackageReference "XCoordinator" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/ReactiveX/RxSwift.git";
repositoryURL = "git@github.com:quickbirdstudios/XCoordinator.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 5.0.1;
};
};
9B5657DD2315FC5C00F4F4F7 /* XCRemoteSwiftPackageReference "XCoordinator" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/quickbirdstudios/XCoordinator.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 2.0.2;
minimumVersion = 2.0.7;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
9B0A75392316C1810092CA3A /* XCoordinatorRx */ = {
2E7649E7240D9A3800F08477 /* CombineCocoa */ = {
isa = XCSwiftPackageProductDependency;
package = 9B5657DD2315FC5C00F4F4F7 /* XCRemoteSwiftPackageReference "XCoordinator" */;
productName = XCoordinatorRx;
package = 2E7649E6240D9A3800F08477 /* XCRemoteSwiftPackageReference "CombineCocoa" */;
productName = CombineCocoa;
};
9B5657D82315FB9700F4F4F7 /* Action */ = {
2E7649EA240D9CA800F08477 /* XCoordinatorCombine */ = {
isa = XCSwiftPackageProductDependency;
package = 9B5657D72315FB9700F4F4F7 /* XCRemoteSwiftPackageReference "Action" */;
productName = Action;
package = 2E7649E9240D9CA800F08477 /* XCRemoteSwiftPackageReference "XCoordinator" */;
productName = XCoordinatorCombine;
};
9B5657DB2315FC1000F4F4F7 /* RxCocoa */ = {
2E7649EC240D9CA800F08477 /* XCoordinator */ = {
isa = XCSwiftPackageProductDependency;
package = 9B5657DA2315FC1000F4F4F7 /* XCRemoteSwiftPackageReference "RxSwift" */;
productName = RxCocoa;
package = 2E7649E9240D9CA800F08477 /* XCRemoteSwiftPackageReference "XCoordinator" */;
productName = XCoordinator;
};
/* End XCSwiftPackageProductDependency section */
};
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion XCoordinator-Example/Models/News.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation
import class UIKit.UIImage

struct News {
struct News: Hashable {
var title: String
var subtitle: String
var image: UIImage
Expand Down
2 changes: 1 addition & 1 deletion XCoordinator-Example/Models/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

import Foundation

struct User {
struct User: Hashable {
var name: String
}
10 changes: 2 additions & 8 deletions XCoordinator-Example/Scenes/About/AboutViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
//

import UIKit
import RxSwift
import RxCocoa
import WebKit
import Combine

class AboutViewController: UIViewController, BindableType {

Expand All @@ -27,10 +26,6 @@ class AboutViewController: UIViewController, BindableType {
UIBarButtonItem(title: "Website", style: .done,
target: self, action: #selector(openWebsite))

// MARK: Stored properties

private let disposeBag = DisposeBag()

// MARK: Overrides

override func viewDidLoad() {
Expand All @@ -52,7 +47,7 @@ class AboutViewController: UIViewController, BindableType {

@objc
private func openWebsite() {
viewModel.input.openWebsiteTrigger.onNext(())
viewModel.input.openWebsiteTrigger.send()
}

// MARK: Helpers
Expand All @@ -71,5 +66,4 @@ class AboutViewController: UIViewController, BindableType {
.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor),
])
}

}
5 changes: 2 additions & 3 deletions XCoordinator-Example/Scenes/About/AboutViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
//

import Foundation
import RxSwift
import Action
import Combine

protocol AboutViewModelInput {
var openWebsiteTrigger: AnyObserver<Void> { get }
var openWebsiteTrigger: PassthroughSubject<Void, Never> { get }
}

protocol AboutViewModelOutput {
Expand Down
21 changes: 8 additions & 13 deletions XCoordinator-Example/Scenes/About/AboutViewModelImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,29 @@
//

import Foundation
import RxSwift
import Action
import XCoordinator
import Combine

class AboutViewModelImpl: AboutViewModel, AboutViewModelInput, AboutViewModelOutput {

// MARK: Inputs

private(set) lazy var openWebsiteTrigger = openWebsiteAction.inputs

// MARK: Actions

private lazy var openWebsiteAction = CocoaAction { [unowned self] in
self.router.rx.trigger(.website)
}


private(set) var openWebsiteTrigger = PassthroughSubject<Void, Never>()

// MARK: Outputs

let url = URL(string: "https://github.com/quickbirdstudios/XCoordinator")!

// MARK: Stored properties

private let router: UnownedRouter<AboutRoute>
private var cancellables = Set<AnyCancellable>()

// MARK: Initialization

init(router: UnownedRouter<AboutRoute>) {
self.router = router
openWebsiteTrigger.sink { [unowned self] _ in
self.router.trigger(.website)
}.store(in: &cancellables)
}

}
29 changes: 14 additions & 15 deletions XCoordinator-Example/Scenes/Home/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// Copyright © 2018 QuickBird Studios. All rights reserved.
//

import RxCocoa
import RxSwift
import Combine
import CombineCocoa
import UIKit

class HomeViewController: UIViewController, BindableType {
Expand All @@ -21,7 +21,7 @@ class HomeViewController: UIViewController, BindableType {

// MARK: Stored properties

private let disposeBag = DisposeBag()
private var cancellables = Set<AnyCancellable>()

// MARK: Overrides

Expand All @@ -34,19 +34,18 @@ class HomeViewController: UIViewController, BindableType {
// MARK: BindableType

func bindViewModel() {
logoutButton.rx.tap
.bind(to: viewModel.input.logoutTrigger)
.disposed(by: disposeBag)

usersButton.rx.tap
.bind(to: viewModel.input.usersTrigger)
.disposed(by: disposeBag)

aboutButton.rx.tap
.bind(to: viewModel.input.aboutTrigger)
.disposed(by: disposeBag)
logoutButton.tapPublisher
.sink(receiveValue: viewModel.input.logoutTrigger.send)
.store(in: &cancellables)

usersButton.tapPublisher
.sink(receiveValue: viewModel.input.usersTrigger.send)
.store(in: &cancellables)

aboutButton.tapPublisher
.sink(receiveValue: viewModel.input.aboutTrigger.send)
.store(in: &cancellables)

viewModel.registerPeek(for: usersButton)
}

}
9 changes: 4 additions & 5 deletions XCoordinator-Example/Scenes/Home/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
// Copyright © 2018 QuickBird Studios. All rights reserved.
//

import Action
import RxSwift
import Combine
import XCoordinator

protocol HomeViewModelInput {
var logoutTrigger: AnyObserver<Void> { get }
var usersTrigger: AnyObserver<Void> { get }
var aboutTrigger: AnyObserver<Void> { get }
var logoutTrigger: PassthroughSubject<Void, Never> { get }
var usersTrigger: PassthroughSubject<Void, Never> { get }
var aboutTrigger: PassthroughSubject<Void, Never> { get }
}

protocol HomeViewModelOutput {}
Expand Down
34 changes: 21 additions & 13 deletions XCoordinator-Example/Scenes/Home/HomeViewModelImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,35 @@
// Copyright © 2018 QuickBird Studios. All rights reserved.
//

import Action
import RxSwift
import Combine
import XCoordinator
import XCoordinatorRx

class HomeViewModelImpl: HomeViewModel, HomeViewModelInput, HomeViewModelOutput {

// MARK: Inputs

private(set) lazy var logoutTrigger = logoutAction.inputs
private(set) lazy var usersTrigger = usersAction.inputs
private(set) lazy var aboutTrigger = aboutAction.inputs
private(set) lazy var logoutTrigger = PassthroughSubject<Void, Never>()
private(set) lazy var usersTrigger = PassthroughSubject<Void, Never>()
private(set) lazy var aboutTrigger = PassthroughSubject<Void, Never>()

// MARK: Actions

private lazy var logoutAction = CocoaAction { [unowned self] in
self.router.rx.trigger(.logout)
private lazy var logoutAction = { [unowned self] in
self.router.trigger(.logout)
}

private lazy var usersAction = CocoaAction { [unowned self] in
self.router.rx.trigger(.users)
private lazy var usersAction = { [unowned self] in
self.router.trigger(.users)
}

private lazy var aboutAction = CocoaAction { [unowned self] in
self.router.rx.trigger(.about)
private lazy var aboutAction = { [unowned self] in
self.router.trigger(.about)
}

// MARK: Stored properties

private let router: UnownedRouter<UserListRoute>
private var cancellables = Set<AnyCancellable>()

// MARK: Initialization

Expand All @@ -46,6 +46,14 @@ class HomeViewModelImpl: HomeViewModel, HomeViewModelInput, HomeViewModelOutput

func registerPeek(for sourceView: Container) {
router.trigger(.registerUsersPeek(from: sourceView))
logoutTrigger
.sink(receiveValue: logoutAction)
.store(in: &cancellables)
usersTrigger
.sink(receiveValue: usersAction)
.store(in: &cancellables)
aboutTrigger
.sink(receiveValue: aboutAction)
.store(in: &cancellables)
}

}
Loading