Here I used @State CGSize values to represent both the viewState and the dragState
struct Example1: View {
@State var viewState: CGSize = .zero
@State var dragState: CGSize = .zero
| import UIKit | |
| import Foundation | |
| // NOTE: This playground shows how to use Swift's AttributedString with Markdown. | |
| // | |
| // This code was used to display Markdown content in the Tot iOS Widget <https://tot.rocks> | |
| // MARK: - Helpful Links | |
| // NOTE: The following links helped me figure this stuff out. |
| import Foundation | |
| import os.log | |
| class URLCacheTest { | |
| let logger = Logger(subsystem: "URLCacheTest", category: "main") | |
| // HTTP HEADERS: | |
| // Date: Wed, 04 Nov 2020 11:13:24 GMT | |
| // Server: Apache | |
| // Strict-Transport-Security: max-age=63072000; includeSubdomains; preload |
| import Accelerate | |
| /// This object provides easy color sampling of the `capturedImage` property of an ARFrame. | |
| /// | |
| /// - Warning: This class is NOT thread safe. The `rawRGBBuffer` property is shared between instances | |
| /// and will cause a lot of headaches if 2 instances try to simultaneously access it. | |
| /// If you need multi-threading, make the shared buffer an instance property instead. | |
| /// Just remember to release it when you're done with it. | |
| class CapturedImageSampler { |
| diff --git a/0084-testable-state-management-ergonomics/PrimeTime/ComposableArchitecture/ComposableArchitecture.swift b/0084-testable-state-management-ergonomics/PrimeTime/ComposableArchitecture/ComposableArchitecture.swift | |
| index db4ab12..ab96c5f 100644 | |
| --- a/0084-testable-state-management-ergonomics/PrimeTime/ComposableArchitecture/ComposableArchitecture.swift | |
| +++ b/0084-testable-state-management-ergonomics/PrimeTime/ComposableArchitecture/ComposableArchitecture.swift | |
| @@ -128,3 +128,24 @@ public func logging<Value, Action>( | |
| }] + effects | |
| } | |
| } | |
| + | |
| + |
| import UIKit | |
| #if canImport(SwiftUI) && DEBUG | |
| import SwiftUI | |
| struct UIViewControllerPreview<ViewController: UIViewController>: UIViewControllerRepresentable { | |
| let viewController: ViewController | |
| init(_ builder: @escaping () -> ViewController) { | |
| viewController = builder() | |
| } |
| extension Store { | |
| public func send<LocalValue>( | |
| _ action: @escaping (LocalValue) -> Action, | |
| binding keyPath: KeyPath<Value, LocalValue> | |
| ) -> Binding<LocalValue> { | |
| Binding( | |
| get: { self.value[keyPath: keyPath] }, | |
| set: { self.send(action($0)) } | |
| ) | |
| } |
| extension View { | |
| func presentation(_ alert: Alert?) -> some View { | |
| guard let alert = alert else { return AnyView(self) } | |
| let binding = Binding<Bool>.constant(true) | |
| return AnyView(self.presentation(binding) { alert }) | |
| } | |
| } |
| func debounce<T>(delay: TimeInterval, function: @escaping (T) -> Void, complete: @escaping () -> Void = { }) -> (T) -> Void { | |
| let queue = DispatchQueue(label: "Debouncer") | |
| var current: DispatchWorkItem? | |
| return { input in | |
| current?.cancel() | |
| let new = DispatchWorkItem { | |
| function(input) | |
| complete() | |
| } |