[Swift4] Expanding CodableHelper with added date and JSON customisations (#3365)

* Expanding CodableHelper with a more customisable dateFormatter and JSON en-/decoder.

* Ran ./bin/swift4-petstore.sh

* Ran ./bin/swift4-petstore-all.sh again after merge from master.

* Ran ./bin/swift4-petstore-all.sh again after building.

* Ran ./bin/swift4-petstore-all.sh again after rebase latest from upstream master.

* sync master, update samples

* Built and ran ./bin/swift4-petstore-all.sh

* Re-adding code which disappeared in rebase from master.

* Fixed test

* [swift] remove old classes
This commit is contained in:
Pelle Stenild Coltau
2019-12-16 10:40:53 +01:00
committed by William Cheng
parent 5f5401bca6
commit f6dbd48b9c
449 changed files with 8733 additions and 1895 deletions

View File

@@ -7,16 +7,16 @@
//
/// Sequence that repeats `repeatedValue` infinite number of times.
struct InfiniteSequence<E> : Sequence {
struct InfiniteSequence<E>: Sequence {
typealias Element = E
typealias Iterator = AnyIterator<E>
private let _repeatedValue: E
init(repeatedValue: E) {
_repeatedValue = repeatedValue
}
func makeIterator() -> Iterator {
let repeatedValue = _repeatedValue
return AnyIterator {

View File

@@ -19,7 +19,7 @@ struct Queue<T>: Sequence {
typealias Generator = AnyIterator<T>
private let _resizeFactor = 2
private var _storage: ContiguousArray<T?>
private var _count = 0
private var _pushNextIndex = 0
@@ -35,50 +35,50 @@ struct Queue<T>: Sequence {
_storage = ContiguousArray<T?>(repeating: nil, count: capacity)
}
private var dequeueIndex: Int {
let index = _pushNextIndex - count
return index < 0 ? index + _storage.count : index
}
/// - returns: Is queue empty.
var isEmpty: Bool {
return count == 0
}
/// - returns: Number of elements inside queue.
var count: Int {
return _count
}
/// - returns: Element in front of a list of elements to `dequeue`.
func peek() -> T {
precondition(count > 0)
return _storage[dequeueIndex]!
}
mutating private func resizeTo(_ size: Int) {
var newStorage = ContiguousArray<T?>(repeating: nil, count: size)
let count = _count
let dequeueIndex = self.dequeueIndex
let spaceToEndOfQueue = _storage.count - dequeueIndex
// first batch is from dequeue index to end of array
let countElementsInFirstBatch = Swift.min(count, spaceToEndOfQueue)
// second batch is wrapped from start of array to end of queue
let numberOfElementsInSecondBatch = count - countElementsInFirstBatch
newStorage[0 ..< countElementsInFirstBatch] = _storage[dequeueIndex ..< (dequeueIndex + countElementsInFirstBatch)]
newStorage[countElementsInFirstBatch ..< (countElementsInFirstBatch + numberOfElementsInSecondBatch)] = _storage[0 ..< numberOfElementsInSecondBatch]
_count = count
_pushNextIndex = count
_storage = newStorage
}
/// Enqueues `element`.
///
/// - parameter element: Element to enqueue.
@@ -86,19 +86,19 @@ struct Queue<T>: Sequence {
if count == _storage.count {
resizeTo(Swift.max(_storage.count, 1) * _resizeFactor)
}
_storage[_pushNextIndex] = element
_pushNextIndex += 1
_count += 1
if _pushNextIndex >= _storage.count {
_pushNextIndex -= _storage.count
}
}
private mutating func dequeueElementOnly() -> T {
precondition(count > 0)
let index = dequeueIndex
defer {
@@ -126,7 +126,7 @@ struct Queue<T>: Sequence {
return dequeueElementOnly()
}
/// - returns: Generator of contained elements.
func makeIterator() -> AnyIterator<T> {
var i = dequeueIndex

View File

@@ -7,7 +7,7 @@
//
/// Represents disposable resource with state tracking.
public protocol Cancelable : Disposable {
public protocol Cancelable: Disposable {
/// Was resource disposed.
var isDisposed: Bool { get }
}

View File

@@ -6,7 +6,7 @@
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//
protocol SynchronizedUnsubscribeType : class {
protocol SynchronizedUnsubscribeType: class {
associatedtype DisposeKey
func synchronizedUnsubscribe(_ disposeKey: DisposeKey)

View File

@@ -9,7 +9,7 @@
/**
Represents an observable sequence wrapper that can be connected and disconnected from its underlying observable sequence.
*/
public protocol ConnectableObservableType : ObservableType {
public protocol ConnectableObservableType: ObservableType {
/**
Connects the observable wrapper to its source. All subscribed observers will receive values from the underlying observable sequence as long as the connection is established.

View File

@@ -10,4 +10,3 @@
public struct Disposables {
private init() {}
}

View File

@@ -9,14 +9,14 @@
/// Represents a disposable that does nothing on disposal.
///
/// Nop = No Operation
fileprivate struct NopDisposable : Disposable {
private struct NopDisposable: Disposable {
fileprivate static let noOp: Disposable = NopDisposable()
fileprivate init() {
}
/// Does nothing.
public func dispose() {
}

View File

@@ -10,9 +10,7 @@ let RxErrorDomain = "RxErrorDomain"
let RxCompositeFailures = "RxCompositeFailures"
/// Generic Rx error codes.
public enum RxError
: Swift.Error
, CustomDebugStringConvertible {
public enum RxError: Swift.Error, CustomDebugStringConvertible {
/// Unknown error occurred.
case unknown
/// Performing an action on disposed object.

View File

@@ -7,10 +7,10 @@
//
/// Creates mutable reference wrapper for any type.
final class RxMutableBox<T> : CustomDebugStringConvertible {
final class RxMutableBox<T>: CustomDebugStringConvertible {
/// Wrapped value
var value : T
var value: T
/// Creates reference wrapper for `value`.
///
/// - parameter value: Value to wrap.

View File

@@ -9,7 +9,7 @@
import struct Foundation.Date
/// Provides a virtual time scheduler that uses `Date` for absolute time and `NSTimeInterval` for relative time.
public class HistoricalScheduler : VirtualTimeScheduler<HistoricalSchedulerTimeConverter> {
public class HistoricalScheduler: VirtualTimeScheduler<HistoricalSchedulerTimeConverter> {
/**
Creates a new historical scheduler with initial clock value.

View File

@@ -6,8 +6,6 @@
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//
protocol ScheduledItemType
: Cancelable
, InvocableType {
protocol ScheduledItemType: Cancelable, InvocableType {
func invoke()
}

View File

@@ -7,15 +7,15 @@
//
/// Represents an object that is both an observable sequence as well as an observer.
public protocol SubjectType : ObservableType {
public protocol SubjectType: ObservableType {
/// The type of the observer that represents this subject.
///
/// Usually this type is type of subject itself, but it doesn't have to be.
associatedtype SubjectObserverType : ObserverType
associatedtype SubjectObserverType: ObserverType
/// Returns observer interface for subject.
///
/// - returns: Observer interface for subject.
func asObserver() -> SubjectObserverType
}