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 | |
var shouldApplyPrivacy: Bool = { | |
#if targetEnvironment(simulator) || DEBUG | |
return false | |
#else | |
return true | |
#endif | |
}() |
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
extension DispatchTimeInterval { | |
var nanoseconds: UInt64 { | |
switch self { | |
case .nanoseconds(let value) where value >= 0: return UInt64(value) | |
case .microseconds(let value) where value >= 0: return UInt64(value) * 1000 | |
case .milliseconds(let value) where value >= 0: return UInt64(value) * 1_000_000 | |
case .seconds(let value) where value >= 0: return UInt64(value) * 1_000_000_000 | |
case .never: return .zero | |
default: return .zero | |
} |
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 SwiftUI | |
struct DetailView : View { | |
var body : some View { | |
// In order for the dismiss to happen, either NavigationView or VStack has to be commented | |
NavigationView { | |
VStack { | |
InnerView() | |
} | |
.navigationTitle("Detail") |
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
Button(action: { | |
self.uiSpin.emit(Event.startCounter) | |
}) { | |
Text("\(self.uiSpin.state.isCounterPaused ? "Start": "Stop")") | |
} | |
// A SwiftUISpin can also be used to produce SwiftUI bindings: | |
Toggle(isOn: self.uiSpin.binding(for: \.isPaused, event: .toggle) { | |
Text("toggle") | |
} |
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
@ObservedObject | |
private var uiSpin: SwiftUISpin<State, Event> = { | |
// previously defined or injected: counterSpin is the Spin that handles our counter business | |
let spin = SwiftUISpin(spin: counterSpin) | |
spin.start() | |
return spin | |
}() |
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
self.uiSpin.emit(Event.startCounter) |
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
// previously defined or injected: counterSpin is the Spin that handles our counter rules | |
self.uiSpin = UISpin(spin: counterSpin) | |
// self.uiSpin is now able to handle UI side effects | |
// we now want to attach the UI Spin to the rendering function of the ViewController: | |
self.uiSpin.render(on: self, using: { $0.render(state:) }) | |
// And once the view is ready (in “viewDidLoad” function for instance) let’s start the loop: | |
self.uiSpin.start() | |
// the underlying reactive stream will be disposed once the uiSpin will be deinit |
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 render(state: State) { | |
switch state { | |
case .increasing(let value): | |
self.counterLabel.text = "\(value)" | |
self.counterLabel.textColor = .green | |
case .decreasing(let value): | |
self.counterLabel.text = "\(value)" | |
self.counterLabel.textColor = .red | |
} | |
} |
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
// With RxSwift | |
Observable | |
.start(spin: levelsSpin) | |
.disposed(by: disposeBag) | |
// With ReactiveSwift | |
SignalProducer | |
.start(spin: levelsSpin) | |
.disposed(by: disposeBag) |
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
let levelsSpin = Spin(initialState: Levels(left: 10, right: 20), reducer: Reducer(levelsReducer)) { | |
Feedback(effect: leftEffect) | |
Feedback(effect: rightEffect) | |
} |
NewerOlder