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
| // | |
| // A Swift property wrapper for adding "indirect" to struct properties. | |
| // Enum supports this out of the box, but for some reason struct doesn't. | |
| // | |
| // This is useful when you want to do something recursive with structs like: | |
| // | |
| // struct Node { | |
| // var next: Node? | |
| // } | |
| // |
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
| /// Wait for async operation to return value and call callback with the value | |
| /// This class is intended to workaround/simplify async/await + actors isolation | |
| /// https://twitter.com/krzyzanowskim/status/1523233140914876416 | |
| private class AsyncWaiter<T> { | |
| var didReceiveValue: Bool = false | |
| let value: (T) -> Void | |
| let operation: () async throws -> T | |
| init(_ value: @escaping (T) -> Void, operation: @escaping () async throws -> T) { | |
| self.value = value |
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
| class ViewController: UIViewController { | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| Task { | |
| // 1️⃣❓ UIViewController is in a MainActor context, so this Task | |
| // will inherit that, so the following pretend expensive call will | |
| // be on the main thread and likely block? | |
| ExpensiveOperationPerformer.doExpensiveLoopAndPrint() | |
| } |
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 | |
| enum ColorAttribute: CodableAttributedStringKey, MarkdownDecodableAttributedStringKey { | |
| enum Value: String, Codable, Hashable { | |
| case red | |
| case orange | |
| case yellow | |
| case green | |
| case mint | |
| case teal |
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 UIKit | |
| struct IceCream { | |
| let title: String | |
| let icon: UIImage | |
| } | |
| struct AppSettings { | |
| static var fontSize = 17.0 | |
| } |
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 Error { | |
| var code: Int { return (self as NSError).code } | |
| var domain: String { return (self as NSError).domain } | |
| var userInfo: [String:Any] { return (self as NSError).userInfo } | |
| func timeAfterWhichToRetry(retryCount: Int) -> TimeInterval? { | |
| // CloudKit suggests us retry too often, so slow us down as we retry a lot, up to 5 minutes | |
| if let suggestedTimeout = suggestedTimeAfterWhichToRetry { | |
| if suggestedTimeAfterWhichToRetry == 0 { | |
| return 0 |
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 | |
| @main | |
| struct testColorSchemeApp: App { | |
| @StateObject private var appearanceManager = AppearanceManager() | |
| var body: some Scene { | |
| WindowGroup { | |
| ContentView() | |
| .environmentObject(appearanceManager) |
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
| // | |
| // RemindersAppIcon.swift | |
| // RemindersAppIcon | |
| // | |
| // Created by David on 1/5/22. | |
| // | |
| import SwiftUI | |
| struct RemindersAppIcon: View { |
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
| // | |
| // PomodoroPicker.swift | |
| // pomodoro | |
| // | |
| // Created by David Rozmajzl on 1/1/22. | |
| // | |
| import SwiftUI | |
| struct PomodoroPicker<Content, Item: Hashable>: View where Content: View { |