Skip to content

Commit a86bf48

Browse files
committed
ReactiveSwift compatability changes.
1 parent 11b6658 commit a86bf48

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

Examples/CaseStudies/SwiftUICaseStudies/00-Core.swift

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Combine
1+
import ReactiveSwift
22
import ComposableArchitecture
33
import UIKit
44

@@ -63,7 +63,7 @@ struct RootEnvironment {
6363
var downloadClient: DownloadClient
6464
var favorite: (UUID, Bool) -> Effect<Bool, Error>
6565
var fetchNumber: () -> Effect<Int, Never>
66-
var mainQueue: AnySchedulerOf<DispatchQueue>
66+
var mainQueue: DateScheduler
6767
var numberFact: (Int) -> Effect<String, NumbersApiError>
6868
var trivia: (Int) -> Effect<String, TriviaApiError>
6969
var userDidTakeScreenshot: Effect<Void, Never>
@@ -75,10 +75,10 @@ struct RootEnvironment {
7575
downloadClient: .live,
7676
favorite: favorite(id:isFavorite:),
7777
fetchNumber: liveFetchNumber,
78-
mainQueue: DispatchQueue.main.eraseToAnyScheduler(),
78+
mainQueue: QueueScheduler.main,
7979
numberFact: liveNumberFact(for:),
8080
trivia: liveTrivia(for:),
81-
userDidTakeScreenshot: liveUserDidTakeScreenshot,
81+
userDidTakeScreenshot: liveUserDidTakeScreenshot.producer,
8282
uuid: UUID.init,
8383
webSocket: .live
8484
)
@@ -253,41 +253,34 @@ let rootReducer = Reducer<RootState, RootAction, RootEnvironment>.combine(
253253
// Typically this live implementation of the dependency would live in its own module so that the
254254
// main feature doesn't need to compile it.
255255
func liveNumberFact(for n: Int) -> Effect<String, NumbersApiError> {
256-
return URLSession.shared.dataTaskPublisher(for: URL(string: "http://numbersapi.com/\(n)/trivia")!)
256+
URLSession.shared.reactive.data(with: URLRequest(url: URL(string: "http://numbersapi.com/\(n)/trivia")!))
257257
.map { data, _ in String(decoding: data, as: UTF8.self) }
258-
.catch { _ in
259-
// Sometimes numbersapi.com can be flakey, so if it ever fails we will just
260-
// default to a mock response.
261-
Just("\(n) is a good number Brent")
262-
.delay(for: 1, scheduler: DispatchQueue.main)
258+
.flatMapError { _ in
259+
Effect(value: "\(n) is a good number Brent")
260+
.delay(1, on: QueueScheduler.main)
263261
}
264-
.mapError { _ in NumbersApiError() }
265-
.eraseToEffect()
262+
.promoteError(NumbersApiError.self)
266263
}
267264

268265
// This is the "live" trivia dependency that reaches into the outside world to fetch trivia.
269266
// Typically this live implementation of the dependency would live in its own module so that the
270267
// main feature doesn't need to compile it.
271268
func liveTrivia(for n: Int) -> Effect<String, TriviaApiError> {
272-
URLSession.shared.dataTaskPublisher(for: URL(string: "http://numbersapi.com/\(n)/trivia")!)
269+
URLSession.shared.reactive.data(with: URLRequest(url: URL(string: "http://numbersapi.com/\(n)/trivia")!))
273270
.map { data, _ in String.init(decoding: data, as: UTF8.self) }
274-
.catch { _ in
275-
// Sometimes numbersapi.com can be flakey, so if it ever fails we will just
276-
// default to a mock response.
277-
Just("\(n) is a good number Brent")
278-
.delay(for: 1, scheduler: DispatchQueue.main)
271+
.flatMapError { _ in
272+
Effect(value: "\(n) is a good number Brent")
273+
.delay(1, on: QueueScheduler.main)
279274
}
280-
.mapError { _ in TriviaApiError() }
281-
.eraseToEffect()
275+
.promoteError(TriviaApiError.self)
282276
}
283277

284278
private func liveFetchNumber() -> Effect<Int, Never> {
285-
Deferred { Just(Int.random(in: 1...1_000)) }
286-
.delay(for: 1, scheduler: DispatchQueue.main)
287-
.eraseToEffect()
279+
Effect.deferred { Effect(value: Int.random(in: 1...1_000)) }
280+
.delay(1, on: QueueScheduler.main)
288281
}
289282

290283
private let liveUserDidTakeScreenshot = NotificationCenter.default
291-
.publisher(for: UIApplication.userDidTakeScreenshotNotification)
284+
.reactive.notifications(forName: UIApplication.userDidTakeScreenshotNotification)
292285
.map { _ in () }
293-
.eraseToEffect()
286+

0 commit comments

Comments
 (0)