Hi, I have an existing app with AppEntities defined, that works on iOS17+. The AppEntities also have EntityPropertyQuery defined, so they work as 'find intents'. I want to use the new @AssistantEntity which is iOS18+ where possible, while supporting the previous versions. What's the best way to do this?
For e.g. I have a 'log' AppEntity:
@available(iOS 17.0, *)
struct CJLogAppEntity: AppEntity {
static var defaultQuery = CJLogAppEntityQuery()
....
}
struct CJLogAppEntityQuery: EntityPropertyQuery {
...
}
How do I adopt this with @AssistantEntity(schema: .journal.entry) for iOS18, while maintaining compatibility with iOS17? I don't want to include two different versions of the same AppEntity. Would it just with with the correct @available annotations on both entities?
You could add the required properties from the journal.entry schema to your CJLogAppEntity and wrap them around the Property macro. This will allow you to share the same struct between iOS 17 and iOS 18+ while conditionally adding the macro on iOS 18+.
Example:
@available(iOS 17.0, *)
struct CJLogAppEntity: AppEntity {
@Property var title: String?
@Property var message: AttributedString?
@Property var mediaItems: [IntentFile]
@Property var entryDate: Date?
@Property var location: CLPlacemark?
}
@AppEntity(schema: .journal.entry)
@available(iOS 18.0, *)
extension CJLogAppEntity {}
Note the code above requires you build with the latest SDK while back-deploying it all the way back to iOS 17.