|
|
|
|
@ -10,39 +10,37 @@ import AppIntents |
|
|
|
|
|
|
|
|
|
@available(iOS 16.0, macOS 13.0, watchOS 9.0, tvOS 16.0, *) |
|
|
|
|
struct TimerIdentifierAppEntity: AppEntity { |
|
|
|
|
|
|
|
|
|
static var typeDisplayRepresentation = TypeDisplayRepresentation(name: "Timer Identifier") |
|
|
|
|
|
|
|
|
|
static var defaultQuery = TimerIdentifierAppEntityQuery() |
|
|
|
|
|
|
|
|
|
var id: String // if your identifier is not a String, conform the entity to EntityIdentifierConvertible. |
|
|
|
|
var displayString: String |
|
|
|
|
var displayRepresentation: DisplayRepresentation { |
|
|
|
|
DisplayRepresentation(title: "\(displayString)") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
init(id: String, displayString: String) { |
|
|
|
|
self.id = id |
|
|
|
|
self.displayString = displayString |
|
|
|
|
} |
|
|
|
|
struct TimerIdentifierAppEntityQuery: EntityQuery { |
|
|
|
|
func entities(for identifiers: [TimerIdentifierAppEntity.ID]) async throws -> [TimerIdentifierAppEntity] { |
|
|
|
|
|
|
|
|
|
let timers = identifiers.compactMap { IntentDataProvider.main.timer(id: $0) } |
|
|
|
|
await PersistenceController.shared.container.performBackgroundTask { context in |
|
|
|
|
let timers = identifiers.compactMap { IntentDataProvider.main.timer(context: context, id: $0) } |
|
|
|
|
return timers.map { TimerIdentifierAppEntity(id: $0.stringId, displayString: $0.displayName) } |
|
|
|
|
// TODO: return TimerIdentifierAppEntity entities with the specified identifiers here. |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func suggestedEntities() async throws -> [TimerIdentifierAppEntity] { |
|
|
|
|
|
|
|
|
|
try await PersistenceController.shared.container.performBackgroundTask { context in |
|
|
|
|
let timers = try IntentDataProvider.main.timers(context: context) |
|
|
|
|
return timers.map { TimerIdentifierAppEntity(id: $0.stringId, displayString: $0.displayName) } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO: return likely TimerIdentifierAppEntity entities here. |
|
|
|
|
// This method is optional; the default implementation returns an empty array. |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static var defaultQuery = TimerIdentifierAppEntityQuery() |
|
|
|
|
|
|
|
|
|
var id: String // if your identifier is not a String, conform the entity to EntityIdentifierConvertible. |
|
|
|
|
var displayString: String |
|
|
|
|
var displayRepresentation: DisplayRepresentation { |
|
|
|
|
DisplayRepresentation(title: "\(displayString)") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
init(id: String, displayString: String) { |
|
|
|
|
self.id = id |
|
|
|
|
self.displayString = displayString |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|