This file contains 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
// Variables used by Scriptable. | |
// These must be at the very top of the file. Do not edit. | |
// icon-color: cyan; icon-glyph: clock; | |
// list of time zones: https://gist.github.com/rxaviers/8481876 | |
let configs = [ | |
{name: "Warsaw", timzeZone: "Europe/Berlin", bgColor: new Color("BF0D3E",1)}, | |
{name: "Recife", timeZone: "America/Recife", bgColor: new Color("009639",1)}, | |
{name: "Los Angeles", timeZone: "America/Los_Angeles", bgColor: new Color("3878d1",1)} | |
] |
This file contains 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 View { | |
@ViewBuilder func modify<Modified: View>( | |
if condition: @autoclosure () -> Bool, | |
then transform: (Self) -> Modified | |
) -> some View { | |
if condition() { | |
transform(self) | |
} else { | |
self | |
} |
This file contains 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 | |
public protocol JSONEncodable: Encodable { | |
static var keyEncodingStrategy: JSONEncoder.KeyEncodingStrategy { get } | |
static var dateEncodingStrategy: JSONEncoder.DateEncodingStrategy { get } | |
static var dataEncodingStrategy: JSONEncoder.DataEncodingStrategy { get } | |
static var nonConformingFloatEncodingStrategy: JSONEncoder.NonConformingFloatEncodingStrategy { get } | |
func toJSON() throws -> Data | |
} |
This file contains 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 Combine | |
public final class CustomPublisher<Output, Failure>: Publisher where Failure: Error { | |
public init(subscribe subscribeClosure: @escaping (AnySubscriber<Output, Failure>) -> Subscription) { | |
self.subscribeClosure = subscribeClosure | |
} | |
public func receive<S>(subscriber: S) where S: Combine.Subscriber, S.Input == Output, S.Failure == Failure { | |
let subscription = subscribeClosure(AnySubscriber(subscriber)) |
This file contains 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 Combine | |
public final class SimplePublisher<Output, Failure>: Publisher where Failure: Error { | |
public init(_ closure: @escaping (Receiver<Output, Failure>) -> Disposable) { | |
self.closure = closure | |
} | |
public func receive<S>(subscriber: S) where S: Subscriber, S.Input == Output, S.Failure == Failure { | |
subscriber.receive(subscription: Subscription(subscriber: subscriber, closure: closure)) | |
} |
This file contains 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 | |
public struct FormattedTextField<Formatter: TextFieldFormatter>: View { | |
public init(_ title: String, | |
value: Binding<Formatter.Value>, | |
formatter: Formatter) { | |
self.title = title | |
self.value = value | |
self.formatter = formatter | |
} |
This file contains 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 | |
public struct NumberField: View { | |
public init(_ title: String, | |
value: Binding<NSNumber?>, | |
decorator: @escaping (String) -> String = { $0 }) { | |
self.title = title | |
self.value = value | |
let formatter = NumberFormatter() |
This file contains 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 Combine | |
import CoreData | |
public final class FetchedResultsPublisher | |
<ResultType> | |
: Publisher | |
where | |
ResultType: NSFetchRequestResult | |
{ | |
This file contains 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 Combine | |
extension Publisher { | |
func materialize() -> Result<[Output], Failure> { | |
var values = [Output]() | |
var result: Result<[Output], Failure>! | |
let semaphore = DispatchSemaphore(value: 0) | |
let subscription = sink(receiveCompletion: { completion in | |
switch completion { |
This file contains 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 | |
func IfLet<T, ThenOut: View>( | |
_ value: T?, | |
then: (T) -> ThenOut | |
) -> some View { | |
ViewBuilder.buildIf(value.map { then($0) }) | |
} | |
func IfLet<T, ThenOut: View, ElseOut: View>( |