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 SwiftData | |
| import CoreSpotlight | |
| import FetchDescriptorObserver | |
| import OSLog | |
| import AppIntents | |
| private let logger = Logger.spotlight | |
| // Initialize from a SwiftData PersistentModel | |
| protocol FromPersistentModel { |
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 FetchDescriptor { | |
| public static func model<Model: PersistentModel & UUIDString>( | |
| withUUIDString uuidString: String? | |
| ) -> FetchDescriptor<Model> { | |
| guard let uuidString else { return .init(predicate: .false) } | |
| let pred = #Predicate<Model> { $0.uuid == uuidString } | |
| var desc = FetchDescriptor<Model>(predicate: pred) | |
| desc.fetchLimit = 1 | |
| return desc | |
| } |
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
| TARGET="[email protected]"; APP="/path/to/DerivedData/.../MyApp.app"; APP_NAME=$(basename "$APP"); rsync -avE --delete "$APP" "$TARGET:/Applications/" && ssh "$TARGET" "echo Remote host: \$(hostname); codesign --force --deep -s - /Applications/$APP_NAME && open -n /Applications/$APP_NAME" |
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
| public extension Task where Success == Void , Failure == Never { | |
| // Suspends until the task is cancelled | |
| static func cancellation() async -> Void { | |
| let s = AsyncStream<Void>{ continuation in } | |
| for await _ in s { | |
| } | |
| } | |
| // EMITS INFINITE ELEMENTS CPU 100% |
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
| // | |
| // EnvironmentDimmedTintColorViewModifier.swift | |
| // Learn | |
| // | |
| // Created by Juan Arzola on 3/17/25. | |
| // Copyright © 2025 Juan Arzola. All rights reserved. | |
| // | |
| import SwiftUI | |
| import UIKit |
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 SwiftData | |
| extension PersistentIdentifier { | |
| var shortDebugDescription: String { | |
| let description = "\(self)" | |
| let entityNameRange = description.firstMatch(of: self.entityName)?.range | |
| let lastParenthesisRange = description.firstMatch(of: ")")?.range | |
| if let entityNameRange, let lastParenthesisRange, | |
| entityNameRange.lowerBound < lastParenthesisRange.upperBound { | |
| return String(description[entityNameRange.lowerBound..<lastParenthesisRange.lowerBound]) |
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 ModelContainer { | |
| // non-throwing version | |
| nonisolated func runNonisolated<ResultType, ActorType: InitWithModelContainer>( | |
| action: @Sendable (_ actor: ActorType) async -> ResultType | |
| ) async -> ResultType { | |
| let actor = ActorType(modelContainer: self) | |
| let result = await action(actor) | |
| return result | |
| } | |
| // throwing version |
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
| // Our one super simple SwiftData Model | |
| @Model | |
| class Item { | |
| ... | |
| } | |
| // MARK: - TodayView | |
| @MainActor |
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
| // MARK: - TodayView | |
| @MainActor | |
| struct TodayView: View { | |
| @State private var viewModel = TodayViewModel() | |
| @Environment(\.modelContext) private var modelContext | |
| var body: some View { | |
| HStack { | |
| switch viewModel.content { |
NewerOlder