mirror of
https://github.com/fxm90/GradientLoadingBar.git
synced 2026-06-16 12:24:31 +00:00
⬆️ :: Update dependencies
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
PODS:
|
||||
- GradientLoadingBar (2.2.3):
|
||||
- LightweightObservable (~> 2.1)
|
||||
- LightweightObservable (2.1.2)
|
||||
- LightweightObservable (2.2.0)
|
||||
- SnapshotTesting (1.9.0)
|
||||
- SwiftConfigurationFiles (0.0.1)
|
||||
- SwiftFormat/CLI (0.49.1)
|
||||
- SwiftLint (0.45.1)
|
||||
- SwiftFormat/CLI (0.49.5)
|
||||
- SwiftLint (0.46.4)
|
||||
|
||||
DEPENDENCIES:
|
||||
- GradientLoadingBar (from `../`)
|
||||
@@ -34,11 +34,11 @@ CHECKOUT OPTIONS:
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
GradientLoadingBar: 157bd321c74e6bd0b0d87de735336060011393ab
|
||||
LightweightObservable: c5ac85423a5edbed9a920b4d5c7b8f94ab3688c4
|
||||
LightweightObservable: a4fce3323002aa57234f3cf5524eecb144cc781f
|
||||
SnapshotTesting: 6141c48b6aa76ead61431ca665c14ab9a066c53b
|
||||
SwiftConfigurationFiles: 1cf2228a911ebed9f42f8dec077bb634f04ca6c8
|
||||
SwiftFormat: 16b41f3229f5e7edb130ac4cd631cceed7af7d5e
|
||||
SwiftLint: 06ac37e4d38c7068e0935bb30cda95f093bec761
|
||||
SwiftFormat: 803e5a44e083cf414b3072381db0e9e65f4c0d0d
|
||||
SwiftLint: b24bab3f5ab5c9ae86a03381bc974d6f0ac85bb0
|
||||
|
||||
PODFILE CHECKSUM: 36b90780cb508f9eaca4f0ac59660e3e748de601
|
||||
|
||||
|
||||
+7
-6
@@ -11,35 +11,36 @@ import Foundation
|
||||
/// Helper to allow storing multiple disposables and matching name from [RxSwift](https://github.com/ReactiveX/RxSwift).
|
||||
public typealias DisposeBag = [Disposable]
|
||||
|
||||
/// Executes a given closure on it's deallocation.
|
||||
/// Calls a closure on when this instance is deallocated.
|
||||
public final class Disposable {
|
||||
// MARK: - Types
|
||||
|
||||
/// Type for closure to be executed on deallocation.
|
||||
/// Type for the closure to be called on deallocation.
|
||||
public typealias Dispose = () -> Void
|
||||
|
||||
// MARK: - Private properties
|
||||
|
||||
/// Closure to be executed on deallocation.
|
||||
/// The closure to be called on deallocation.
|
||||
private let dispose: Dispose
|
||||
|
||||
// MARK: - Initializer
|
||||
|
||||
/// Creates a new instance.
|
||||
///
|
||||
/// - Parameter dispose: The closure that is executed on deallocation.
|
||||
/// - Parameter dispose: The closure that is called on deallocation.
|
||||
public init(_ dispose: @escaping Dispose) {
|
||||
self.dispose = dispose
|
||||
}
|
||||
|
||||
/// Executes our closure.
|
||||
deinit {
|
||||
dispose()
|
||||
}
|
||||
|
||||
// MARK: - Public methods
|
||||
|
||||
/// Adds the current instance to the given array of disposables.
|
||||
/// Adds the current instance to the given array of `Disposable`.
|
||||
///
|
||||
/// - Parameter bag: Reference to the array of `Disposable`.
|
||||
public func disposed(by bag: inout DisposeBag) {
|
||||
bag.append(self)
|
||||
}
|
||||
Generated
+64
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// Observable+Combine.swift
|
||||
// LightweightObservable
|
||||
//
|
||||
// Created by Felix Mau on 04.02.22.
|
||||
// Copyright © 2022 Felix Mau. All rights reserved.
|
||||
//
|
||||
|
||||
import Combine
|
||||
|
||||
// Based on:
|
||||
// https://thoughtbot.com/blog/lets-build-a-custom-publisher-in-combine
|
||||
|
||||
@available(iOS 13.0, *)
|
||||
extension Observable: Publisher {
|
||||
public typealias Output = T
|
||||
public typealias Failure = Never
|
||||
|
||||
public func receive<S: Subscriber>(subscriber: S) where S.Input == Output, S.Failure == Failure {
|
||||
let subscription = Subscription(subscriber: subscriber)
|
||||
subscriber.receive(subscription: subscription)
|
||||
|
||||
// We explicitly subscribe to our `Observable` instance after passing the `Combine.Subscription` to the `Combine.Subscriber`.
|
||||
// This makes sure when the underlying type of the `Observable` is a `Variable´, we correctly forward the initial value.
|
||||
subscription.subscribe(to: self)
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 13.0, *)
|
||||
private extension Observable {
|
||||
/// A custom subscription to forward events from an `Observable` instance.
|
||||
final class Subscription<S: Subscriber> where S.Input == Output, S.Failure == Failure {
|
||||
private var subscriber: S?
|
||||
private var disposable: Disposable?
|
||||
|
||||
init(subscriber: S) {
|
||||
self.subscriber = subscriber
|
||||
}
|
||||
|
||||
/// Updates our `subscriber` (`Combine.Subscriber`) with the values from the observable.
|
||||
///
|
||||
/// - Note: We explicitly avoid storing a reference to the observable from this instance (`Combine.Subscription`),
|
||||
/// as this would create a retain cycle!!
|
||||
func subscribe(to observable: Observable<S.Input>) {
|
||||
disposable = observable.subscribe { [weak self] value, _ in
|
||||
_ = self?.subscriber?.receive(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 13.0, *)
|
||||
extension Observable.Subscription: Subscription {
|
||||
func request(_: Subscribers.Demand) {
|
||||
// This subscription doesn't respond to demand, since it'll only emit events
|
||||
// according to its underlying `Observable` instance.
|
||||
}
|
||||
|
||||
func cancel() {
|
||||
// When the subscription was cancelled, we'll release the reference to our observable-subscription
|
||||
// in order to prevent any additional events from being sent.
|
||||
disposable = nil
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -30,7 +30,7 @@ public extension Observable where T: Equatable {
|
||||
/// - observer: The closure that is notified on changes if the filter succeeds.
|
||||
///
|
||||
/// - Note:
|
||||
/// The `oldValue` of the observer always contains the previous value that passed the filter! E.g. if you filter for even numbers:
|
||||
/// The `oldValue` of the observer always contains the previous value that passed the filter! E.g. if you filter for **even numbers**:
|
||||
/// ```
|
||||
/// | Emitted values: | 0 | 1 | 2 | 3 | 4 | 5 |
|
||||
/// | -------------------------- | -------- | -------- | -------- | -------- | -------- | -------- |
|
||||
+13
-4
@@ -38,8 +38,6 @@ public class Observable<T> {
|
||||
/// The current (readonly) value of the observable (if available).
|
||||
///
|
||||
/// - Note: We're using a computed property here, cause we need to override this property without nullability in the subclass `Variable`.
|
||||
///
|
||||
/// - Attention: It's always better to subscribe to a given observable! This **shortcut** should only be used during **testing**.
|
||||
public var value: Value? {
|
||||
fatalError("⚠️ – Trying to access an abstract property! Subclasses need to overwrite and implement this computed property.")
|
||||
}
|
||||
@@ -61,6 +59,14 @@ public class Observable<T> {
|
||||
|
||||
// MARK: - Public methods
|
||||
|
||||
/// Updates the current value.
|
||||
///
|
||||
/// - Parameter value: The new value to apply.
|
||||
public func update(_: Value) {
|
||||
// swiftlint:disable:previous unavailable_function
|
||||
fatalError("⚠️ – Trying to call an abstract function! Subclasses need to overwrite and implement this method.")
|
||||
}
|
||||
|
||||
/// Informs the given observer on changes to our underlying property `value`.
|
||||
///
|
||||
/// - Parameter observer: The closure that is notified on changes.
|
||||
@@ -111,8 +117,7 @@ public final class PublishSubject<T>: Observable<T> {
|
||||
|
||||
// MARK: - Public methods
|
||||
|
||||
/// Updates the publish subject using the given value.
|
||||
public func update(_ value: Value) {
|
||||
override public func update(_ value: Value) {
|
||||
let oldValue = _value
|
||||
_value = value
|
||||
|
||||
@@ -156,6 +161,10 @@ public final class Variable<T>: Observable<T> {
|
||||
|
||||
// MARK: - Public methods
|
||||
|
||||
override public func update(_ value: Value) {
|
||||
self.value = value
|
||||
}
|
||||
|
||||
override public func subscribe(_ observer: @escaping Observer) -> Disposable {
|
||||
let disposable = super.subscribe(observer)
|
||||
|
||||
+52
-18
@@ -2,7 +2,7 @@
|
||||
|
||||
<p align="center">
|
||||
<img src="https://img.shields.io/badge/Swift-5.0-green.svg?style=flat" alt="Swift Version" />
|
||||
<img src="http://img.shields.io/travis/com/fxm90/LightweightObservable.svg?style=flat" alt="CI Status" />
|
||||
<img src="https://img.shields.io/github/workflow/status/fxm90/LightweightObservable/Continuous%20Integration" alt="CI Status" />
|
||||
<img src="https://img.shields.io/codecov/c/github/fxm90/LightweightObservable.svg?style=flat" alt="Code Coverage" />
|
||||
<img src="https://img.shields.io/cocoapods/v/LightweightObservable.svg?style=flat" alt="Version" />
|
||||
<img src="https://img.shields.io/cocoapods/l/LightweightObservable.svg?style=flat" alt="License" />
|
||||
@@ -28,6 +28,39 @@ To run the example project, clone the repo, and open the workspace from the Exam
|
||||
- Xcode 10.2+
|
||||
- iOS 9.0+
|
||||
|
||||
### Projects targeting iOS >= 13.0
|
||||
In case your minimum required version is greater equal iOS 13.0, I recommend using [Combine](https://developer.apple.com/documentation/combine) instead of adding `Lightweight Observable` as a dependency.
|
||||
|
||||
If you rely on having a current and previous value in your subscription closure, please have a look at this extension: [Combine+Pairwise.swift](https://gist.github.com/fxm90/be62335d987016c84d2f8b3731197c98).
|
||||
|
||||
#### Update: Since version `2.2` an `Observable` instance conforms to the [`Publisher`](https://developer.apple.com/documentation/combine/publisher) protocol from Swift's `Combine` 🎉
|
||||
|
||||
This makes transitioning from `LightweightObservable` to `Combine` a lot easier, as you can use features from `Combine` without having to change the underlying `Observable` to a `Publisher`.
|
||||
|
||||
Example Code for using `Combine` functions on an instance of `PublishSubject`:
|
||||
|
||||
```swift
|
||||
var subscriptions = Set<AnyCancellable>()
|
||||
|
||||
let publishSubject = PublishSubject<Int>()
|
||||
publishSubject
|
||||
.map { $0 * 2 }
|
||||
.sink { print($0) }
|
||||
.store(in: &subscriptions)
|
||||
|
||||
publishSubject.update(1) // Prints "2"
|
||||
publishSubject.update(2) // Prints "4"
|
||||
publishSubject.update(3) // Prints "6"
|
||||
```
|
||||
|
||||
**Cheatsheet**
|
||||
|
||||
| `LightweightObservable` | `Combine` |
|
||||
| ----------------------- | --------------------- |
|
||||
| `PublishSubject` | `PassthroughSubject` |
|
||||
| `Variable` | `CurrentValueSubject` |
|
||||
|
||||
|
||||
### Integration
|
||||
##### CocoaPods
|
||||
[CocoaPods](https://cocoapods.org) is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate Lightweight Observable into your Xcode project using CocoaPods, specify it in your `Podfile`:
|
||||
@@ -84,6 +117,8 @@ let formattedTimeSubject = Variable("4:20 PM")
|
||||
// ...
|
||||
|
||||
formattedTimeSubject.value = "4:21 PM"
|
||||
// or
|
||||
formattedTimeSubject.update("4:21 PM")
|
||||
```
|
||||
|
||||
#### – Create an `Observable`
|
||||
@@ -227,43 +262,42 @@ XCTAssertEqual(viewModel.formattedTime.value, "4:20")
|
||||
Using the given approach, your view-model could look like this:
|
||||
|
||||
```swift
|
||||
class TimeViewModel {
|
||||
final class ViewModel {
|
||||
// MARK: - Public properties
|
||||
|
||||
/// The current time as a formatted string (**immutable**).
|
||||
var formattedTime: Observable<String> {
|
||||
formattedTimeSubject
|
||||
/// The current date and time as a formatted string (**immutable**).
|
||||
var formattedDate: Observable<String> {
|
||||
formattedDateSubject
|
||||
}
|
||||
|
||||
// MARK: - Private properties
|
||||
|
||||
/// The current time as a formatted string (**mutable**).
|
||||
private let formattedTimeSubject: Variable<String> = Variable("\(Date())")
|
||||
/// The current date and time as a formatted string (**mutable**).
|
||||
private let formattedDateSubject: Variable<String> = Variable("\(Date())")
|
||||
|
||||
private var timer: Timer?
|
||||
|
||||
// MARK: - Initializer
|
||||
|
||||
init() {
|
||||
// Update variable with current time every second.
|
||||
timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block: { [weak self] _ in
|
||||
self?.formattedTimeSubject.value = "\(Date())"
|
||||
})
|
||||
// Update variable with current date and time every second.
|
||||
timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { [weak self] _ in
|
||||
self?.formattedDateSubject.value = "\(Date())"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
And your view controller like this:
|
||||
|
||||
```swift
|
||||
class TimeViewController: UIViewController {
|
||||
final class ViewController: UIViewController {
|
||||
// MARK: - Outlets
|
||||
|
||||
@IBOutlet private var timeLabel: UILabel!
|
||||
@IBOutlet private var dateLabel: UILabel!
|
||||
|
||||
// MARK: - Private properties
|
||||
|
||||
/// The view model calculating the current time.
|
||||
private let timeViewModel = TimeViewModel()
|
||||
private let viewModel = ViewModel()
|
||||
|
||||
/// The dispose bag for this view controller. On it's deallocation, it removes the
|
||||
/// subscription-closures from the corresponding observable-properties.
|
||||
@@ -274,9 +308,9 @@ class TimeViewController: UIViewController {
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
timeViewModel
|
||||
.formattedTime
|
||||
.bind(to: \.text, on: timeLabel)
|
||||
viewModel
|
||||
.formattedDate
|
||||
.bind(to: \.text, on: dateLabel)
|
||||
.disposed(by: &disposeBag)
|
||||
}
|
||||
```
|
||||
|
||||
Generated
+6
-6
@@ -1,11 +1,11 @@
|
||||
PODS:
|
||||
- GradientLoadingBar (2.2.3):
|
||||
- LightweightObservable (~> 2.1)
|
||||
- LightweightObservable (2.1.2)
|
||||
- LightweightObservable (2.2.0)
|
||||
- SnapshotTesting (1.9.0)
|
||||
- SwiftConfigurationFiles (0.0.1)
|
||||
- SwiftFormat/CLI (0.49.1)
|
||||
- SwiftLint (0.45.1)
|
||||
- SwiftFormat/CLI (0.49.5)
|
||||
- SwiftLint (0.46.4)
|
||||
|
||||
DEPENDENCIES:
|
||||
- GradientLoadingBar (from `../`)
|
||||
@@ -34,11 +34,11 @@ CHECKOUT OPTIONS:
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
GradientLoadingBar: 157bd321c74e6bd0b0d87de735336060011393ab
|
||||
LightweightObservable: c5ac85423a5edbed9a920b4d5c7b8f94ab3688c4
|
||||
LightweightObservable: a4fce3323002aa57234f3cf5524eecb144cc781f
|
||||
SnapshotTesting: 6141c48b6aa76ead61431ca665c14ab9a066c53b
|
||||
SwiftConfigurationFiles: 1cf2228a911ebed9f42f8dec077bb634f04ca6c8
|
||||
SwiftFormat: 16b41f3229f5e7edb130ac4cd631cceed7af7d5e
|
||||
SwiftLint: 06ac37e4d38c7068e0935bb30cda95f093bec761
|
||||
SwiftFormat: 803e5a44e083cf414b3072381db0e9e65f4c0d0d
|
||||
SwiftLint: b24bab3f5ab5c9ae86a03381bc974d6f0ac85bb0
|
||||
|
||||
PODFILE CHECKSUM: 36b90780cb508f9eaca4f0ac59660e3e748de601
|
||||
|
||||
|
||||
+413
-409
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Generated
+17
-2
@@ -211,7 +211,7 @@ Alternatively, if you prefer not to use Homebrew, you'll find the latest version
|
||||
|
||||
**Usage:**
|
||||
|
||||
Once you have launched the app and restarted Xcode, you'll find a SwiftFormat option under Xcode's Editor menu.
|
||||
Once you have launched the app and restarted Xcode, you'll find a SwiftFormat option under Xcode's Editor menu. If the SwiftFormat menu does not appear [this thread](https://github.com/nicklockwood/SwiftFormat/issues/494) may help.
|
||||
|
||||
You can configure the formatting [rules](#rules) and [options](#options) using the SwiftFormat for Xcode host application. There is currently no way to override these per-project, however, you can import and export different configurations using the File menu. You will need to do this again each time you switch projects.
|
||||
|
||||
@@ -446,7 +446,13 @@ Alternatively, you can use the line continuation character `\` to wrap a single
|
||||
redundantSelf
|
||||
```
|
||||
|
||||
To avoid automatically opting-in to new rules when SwiftFormat is updated, use the`--rules` argument to *only* enable the rules you specify:
|
||||
To avoid automatically opting-in to new rules when SwiftFormat is updated, you can disable all rules using:
|
||||
|
||||
```bash
|
||||
--disable all
|
||||
```
|
||||
|
||||
And then individually enable just the rules you want. Alternatively, use the`--rules` argument to *only* enable the rules you specify:
|
||||
|
||||
```bash
|
||||
--rules indent,linebreaks
|
||||
@@ -623,6 +629,13 @@ By default, `--lint` will only report lines that require formatting, but you can
|
||||
|
||||
If you would prefer not to see a warning for each and every formatting change, you can use the `--quiet` flag to suppress all output except errors.
|
||||
|
||||
Sometimes you may wish to autoformat some rules, but only lint others. To do that, use the `--lintonly` option in your config file to specify rules that should only be applied in `--lint` mode:
|
||||
|
||||
```
|
||||
--rules braces,indent
|
||||
--lintonly trailingClosures,unusedArguments
|
||||
```
|
||||
|
||||
|
||||
Error codes
|
||||
-----------
|
||||
@@ -766,6 +779,8 @@ Q. I don't want to be surprised by new rules added when I upgrade SwiftFormat. H
|
||||
Known issues
|
||||
---------------
|
||||
|
||||
* When using the Xcode Source Editor Extension, the SwiftFormat menu sometimes disappears from Xcode. If this happens, try moving or renaming Xcode temporarily and then changing it back. Failing that, the suggestions in [this thread](https://github.com/nicklockwood/SwiftFormat/issues/494) may help.
|
||||
|
||||
* The `redundantType` rule can introduce ambiguous code in certain cases when using the default mode of `--redundanttype inferred`. This can be worked around by by using `--redundanttype explicit`, or by manually removing the redundant type reference on the affected line, or by using the `// swiftformat:disable:next redundantType` comment directive to disable the rule at the call site (or just disable the `redundantType` rule completely).
|
||||
|
||||
* If a type initializer or factory method returns an implicitly unwrapped optional value then the `redundantType` rule may remove the explicit type in a situation where it's actually required. To work around this you can either use `--redundanttype explicit`, or use the `// swiftformat:disable:next redundantType` comment directive to disable the rule at the call site (or just disable the `redundantType` rule completely).
|
||||
|
||||
Generated
BIN
Binary file not shown.
+1
-1
@@ -15,7 +15,7 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>2.1.2</string>
|
||||
<string>2.2.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
|
||||
Reference in New Issue
Block a user