Skip to content

Commit

Permalink
Update to Swift 5.0 & remove Result (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
konrad-em authored and sergdort committed Sep 23, 2019
1 parent c376426 commit 6a6d641
Show file tree
Hide file tree
Showing 21 changed files with 123 additions and 157 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ references:
jobs:
build:
macos:
xcode: "10.2.0"
xcode: "10.3.0"
working_directory: /Users/distiller/project
shell: /bin/bash --login -eo pipefail
steps:
Expand Down
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.2
5.0
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "ReactiveCocoa/ReactiveSwift" ~> 5.0
github "ReactiveCocoa/ReactiveSwift" ~> 6.0
2 changes: 1 addition & 1 deletion Cartfile.private
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Example app.
github "ReactiveCocoa/ReactiveCocoa" ~> 9.0.0
github "ReactiveCocoa/ReactiveCocoa" ~> 10.0.0
github "onevcat/Kingfisher" ~> 5.2

# Tests
Expand Down
9 changes: 4 additions & 5 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
github "Quick/Nimble" "v8.0.1"
github "ReactiveCocoa/ReactiveCocoa" "9.0.0"
github "ReactiveCocoa/ReactiveSwift" "5.0.1"
github "antitypical/Result" "4.1.0"
github "onevcat/Kingfisher" "5.3.1"
github "Quick/Nimble" "v8.0.4"
github "ReactiveCocoa/ReactiveCocoa" "10.0.0"
github "ReactiveCocoa/ReactiveSwift" "6.1.0"
github "onevcat/Kingfisher" "5.7.1"
33 changes: 16 additions & 17 deletions Example/PaginationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import ReactiveSwift
import ReactiveCocoa
import Kingfisher
import ReactiveFeedback
import enum Result.NoError

final class PaginationViewController: UICollectionViewController {
let dataSource = ArrayCollectionViewDataSource<Movie>()
let viewModel = PaginationViewModel()
private let (retrySignal, retryObserver) = Signal<Void, NoError>.pipe()
private let (retrySignal, retryObserver) = Signal<Void, Never>.pipe()

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -60,8 +59,8 @@ final class PaginationViewModel {
private var lifetime: Lifetime {
return Lifetime(token)
}
private let nearBottomObserver: Signal<Void, NoError>.Observer
private let retryObserver: Signal<Void, NoError>.Observer
private let nearBottomObserver: Signal<Void, Never>.Observer
private let retryObserver: Signal<Void, Never>.Observer

private let stateProperty: Property<State>
let movies: Property<[Movie]>
Expand All @@ -81,8 +80,8 @@ final class PaginationViewModel {
}

init() {
let (nearBottomSignal, nearBottomObserver) = Signal<Void, NoError>.pipe()
let (retrySignal, retryObserver) = Signal<Void, NoError>.pipe()
let (nearBottomSignal, nearBottomObserver) = Signal<Void, Never>.pipe()
let (retrySignal, retryObserver) = Signal<Void, Never>.pipe()
let feedbacks = [
Feedbacks.loadNextFeedback(for: nearBottomSignal),
Feedbacks.pagingFeedback(),
Expand All @@ -104,15 +103,15 @@ final class PaginationViewModel {
}

enum Feedbacks {
static func loadNextFeedback(for nearBottomSignal: Signal<Void, NoError>) -> Feedback<State, Event> {
static func loadNextFeedback(for nearBottomSignal: Signal<Void, Never>) -> Feedback<State, Event> {
return Feedback(predicate: { !$0.paging }) { _ in
nearBottomSignal
.map { Event.startLoadingNextPage }
}
}

static func pagingFeedback() -> Feedback<State, Event> {
return Feedback<State, Event>(skippingRepeated: { $0.nextPage }) { (nextPage) -> SignalProducer<Event, NoError> in
return Feedback<State, Event>(skippingRepeated: { $0.nextPage }) { (nextPage) -> SignalProducer<Event, Never> in
URLSession.shared.fetchMovies(page: nextPage)
.map(Event.response)
.flatMapError { error in
Expand All @@ -121,14 +120,14 @@ final class PaginationViewModel {
}
}

static func retryFeedback(for retrySignal: Signal<Void, NoError>) -> Feedback<State, Event> {
return Feedback<State, Event>(skippingRepeated: { $0.lastError }) { _ -> Signal<Event, NoError> in
static func retryFeedback(for retrySignal: Signal<Void, Never>) -> Feedback<State, Event> {
return Feedback<State, Event>(skippingRepeated: { $0.lastError }) { _ -> Signal<Event, Never> in
retrySignal.map { Event.retry }
}
}

static func retryPagingFeedback() -> Feedback<State, Event> {
return Feedback<State, Event>(skippingRepeated: { $0.retryPage }) { (nextPage) -> SignalProducer<Event, NoError> in
return Feedback<State, Event>(skippingRepeated: { $0.retryPage }) { (nextPage) -> SignalProducer<Event, Never> in
URLSession.shared.fetchMovies(page: nextPage)
.map(Event.response)
.flatMapError { error in
Expand Down Expand Up @@ -297,7 +296,7 @@ final class MoviewCell: UICollectionViewCell {
}

extension UIScrollView {
var rac_contentOffset: Signal<CGPoint, NoError> {
var rac_contentOffset: Signal<CGPoint, Never> {
return self.reactive.signal(forKeyPath: "contentOffset")
.filterMap { change in
guard let value = change as? NSValue else {
Expand All @@ -307,7 +306,7 @@ extension UIScrollView {
}
}

var rac_nearBottomSignal: Signal<Void, NoError> {
var rac_nearBottomSignal: Signal<Void, Never> {
func isNearBottomEdge(scrollView: UIScrollView, edgeOffset: CGFloat = 44.0) -> Bool {
return scrollView.contentOffset.y + scrollView.frame.size.height + edgeOffset > scrollView.contentSize.height
}
Expand Down Expand Up @@ -406,7 +405,7 @@ extension URLSession {
}

extension UICollectionView {
func rac_items<DataSource:RACCollectionViewDataSourceType & UICollectionViewDataSource, S:SignalProtocol>(dataSource: DataSource) -> (S) -> Disposable? where S.Error == NoError, S.Value == DataSource.Element {
func rac_items<DataSource:RACCollectionViewDataSourceType & UICollectionViewDataSource, S:SignalProtocol>(dataSource: DataSource) -> (S) -> Disposable? where S.Error == Never, S.Value == DataSource.Element {
return { source in
self.dataSource = dataSource
return source.signal.observe({ [weak self] (event) in
Expand All @@ -418,7 +417,7 @@ extension UICollectionView {
}
}

func rac_items<DataSource:RACCollectionViewDataSourceType & UICollectionViewDataSource, S:SignalProducerProtocol>(dataSource: DataSource) -> (S) -> Disposable? where S.Error == NoError, S.Value == DataSource.Element {
func rac_items<DataSource:RACCollectionViewDataSourceType & UICollectionViewDataSource, S:SignalProducerProtocol>(dataSource: DataSource) -> (S) -> Disposable? where S.Error == Never, S.Value == DataSource.Element {
return { source in
self.dataSource = dataSource
return source.producer.start { [weak self] event in
Expand All @@ -434,7 +433,7 @@ extension UICollectionView {
public protocol RACCollectionViewDataSourceType {
associatedtype Element

func collectionView(_ collectionView: UICollectionView, observedEvent: Signal<Element, NoError>.Event)
func collectionView(_ collectionView: UICollectionView, observedEvent: Signal<Element, Never>.Event)
}

final class ArrayCollectionViewDataSource<T>: NSObject, UICollectionViewDataSource {
Expand Down Expand Up @@ -463,7 +462,7 @@ final class ArrayCollectionViewDataSource<T>: NSObject, UICollectionViewDataSour
}

extension ArrayCollectionViewDataSource: RACCollectionViewDataSourceType {
func collectionView(_ collectionView: UICollectionView, observedEvent: Signal<[T], NoError>.Event) {
func collectionView(_ collectionView: UICollectionView, observedEvent: Signal<[T], Never>.Event) {
switch observedEvent {
case .value(let value):
update(with: value)
Expand Down
7 changes: 3 additions & 4 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import UIKit
import ReactiveSwift
import ReactiveCocoa
import ReactiveFeedback
import enum Result.NoError

enum Event {
case increment
Expand All @@ -22,11 +21,11 @@ class ViewController: UIViewController {
@IBOutlet weak var minusButton: UIButton!
@IBOutlet weak var label: UILabel!

private var incrementSignal: Signal<Void, NoError> {
private var incrementSignal: Signal<Void, Never> {
return plusButton.reactive.controlEvents(.touchUpInside).map { _ in }
}

private var decrementSignal: Signal<Void, NoError> {
private var decrementSignal: Signal<Void, Never> {
return minusButton.reactive.controlEvents(.touchUpInside).map { _ in }
}

Expand All @@ -45,7 +44,7 @@ final class ViewModel {
private let state: Property<Int>
let counter: Property<String>

init(increment: Signal<Void, NoError>, decrement: Signal<Void, NoError>) {
init(increment: Signal<Void, Never>, decrement: Signal<Void, Never>) {

let incrementFeedback = Feedback<Int, Event>(predicate: { $0 < 10}) { _ in
increment.map { _ in Event.increment }
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'

gem 'xcpretty'
gem 'cocoapods', '~> 1.6.1'
gem 'cocoapods', '~> 1.6.2'
39 changes: 24 additions & 15 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,40 +1,49 @@
{
"object": {
"pins": [
{
"package": "CwlCatchException",
"repositoryURL": "https://github.com/mattgallagher/CwlCatchException.git",
"state": {
"branch": null,
"revision": "7cd2f8cacc4d22f21bc0b2309c3b18acf7957b66",
"version": "1.2.0"
}
},
{
"package": "CwlPreconditionTesting",
"repositoryURL": "https://github.com/mattgallagher/CwlPreconditionTesting.git",
"state": {
"branch": null,
"revision": "c228db5d2ad1b01ebc84435e823e6cca4e3db98b",
"version": "1.2.0"
}
},
{
"package": "Nimble",
"repositoryURL": "https://github.com/Quick/Nimble.git",
"state": {
"branch": null,
"revision": "43304bf2b1579fd555f2fdd51742771c1e4f2b98",
"version": "8.0.1"
"revision": "6abeb3f5c03beba2b9e4dbe20886e773b5b629b6",
"version": "8.0.4"
}
},
{
"package": "Quick",
"repositoryURL": "https://github.com/Quick/Quick.git",
"state": {
"branch": null,
"revision": "0b4ed6c706dd0cce923b5019a605a9bcc6b1b600",
"version": "2.0.0"
"revision": "33682c2f6230c60614861dfc61df267e11a1602f",
"version": "2.2.0"
}
},
{
"package": "ReactiveSwift",
"repositoryURL": "https://github.com/ReactiveCocoa/ReactiveSwift",
"state": {
"branch": null,
"revision": "c37950dc5020544c58d4bf47c0d028893686b9e6",
"version": "5.0.1"
}
},
{
"package": "Result",
"repositoryURL": "https://github.com/antitypical/Result.git",
"state": {
"branch": null,
"revision": "2ca499ba456795616fbc471561ff1d963e6ae160",
"version": "4.1.0"
"revision": "b772fa0b624926e6e2f21acbb79297736a05c585",
"version": "6.1.0"
}
}
]
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ let package = Package(
.library(name: "ReactiveFeedback", targets: ["ReactiveFeedback"]),
],
dependencies: [
.package(url: "https://github.com/ReactiveCocoa/ReactiveSwift", from: "5.0.0"),
.package(url: "https://github.com/ReactiveCocoa/ReactiveSwift", from: "6.0.0"),
.package(url: "https://github.com/Quick/Nimble.git", from: "8.0.0"),
],
targets: [
.target(name: "ReactiveFeedback", dependencies: ["ReactiveSwift"], path: "ReactiveFeedback"),
.testTarget(name: "ReactiveFeedbackTests", dependencies: ["ReactiveFeedback", "ReactiveSwift", "Nimble"], path: "ReactiveFeedbackTests"),
],
swiftLanguageVersions: [4]
swiftLanguageVersions: [5]
)
6 changes: 3 additions & 3 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ install! 'cocoapods',
use_frameworks!

def shared_pods
pod "ReactiveSwift", "~> 5.0"
pod "ReactiveSwift", "~> 6.0"
end

target "Example" do
Expand All @@ -26,7 +26,7 @@ end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.2'
config.build_settings['SWIFT_VERSION'] = '5.0'
end
end
end
end
14 changes: 5 additions & 9 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
PODS:
- Kingfisher (4.10.1)
- Nimble (8.0.1)
- ReactiveSwift (5.0.1):
- Result (~> 4.1)
- Result (4.1.0)
- ReactiveSwift (6.1.0)

DEPENDENCIES:
- Kingfisher
- Nimble (~> 8.0)
- ReactiveSwift (~> 5.0)
- ReactiveSwift (~> 6.0)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
- Kingfisher
- Nimble
- ReactiveSwift
- Result

SPEC CHECKSUMS:
Kingfisher: c148cd7b47ebde9989f6bc7c27dcaa79d81279a0
Nimble: 45f786ae66faa9a709624227fae502db55a8bdd0
ReactiveSwift: cac20a5bbe560c5806bd29c0fccf90d03b996ac1
Result: bd966fac789cc6c1563440b348ab2598cc24d5c7
ReactiveSwift: b78c7259f8ca46368238c895ae33a6a3bf9f811c

PODFILE CHECKSUM: c48887843d650c5ab915d0ed50cb30912a276222
PODFILE CHECKSUM: 33df60e5cfccc8aaf4daadf97c10923592f1ed87

COCOAPODS: 1.6.1
COCOAPODS: 1.6.2
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The goal of this library is to provide a simple and intuitive approach to design

### Core Concepts

##### State
##### State

`State` is the single source of truth. It represents a state of your system and is usually a plain Swift type (which doesn't contain any ReactiveSwift primitives). Your state is immutable. The only way to transition from one `State` to another is to emit an `Event`.

Expand Down Expand Up @@ -63,7 +63,7 @@ enum Event {
}
```

##### Reducer
##### Reducer

A Reducer is a pure function with a signature of `(State, Event) -> State`. While `Event` represents an action that results in a `State` change, it's actually not what _causes_ the change. An `Event` is just that, a representation of the intention to transition from one state to another. What actually causes the `State` to change, the embodiment of the corresponding `Event`, is a Reducer. A Reducer is the only place where a `State` can be changed.

Expand Down
4 changes: 2 additions & 2 deletions ReactiveFeedback.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "ReactiveFeedback"
s.version = "0.6.0"
s.version = "0.7.0"
s.summary = "Unidirectional reactive architecture"

s.description = <<-DESC
Expand All @@ -18,5 +18,5 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/Babylonpartners/ReactiveFeedback.git", :tag => "#{s.version}" }
s.source_files = "ReactiveFeedback/*.{swift}"

s.dependency "ReactiveSwift", "~> 5.0"
s.dependency "ReactiveSwift", "~> 6.0"
end
Loading

0 comments on commit 6a6d641

Please sign in to comment.