Also fell into this scenario recently. The setup was:
‘Application’
The classes were wrapped in ‘@available’, but similar to you, this didn’t solve the import issue - making the app crash instantly. I had to move my code that interacts with SwiftData into its own target.
I found a solution which was:
‘Application’
‘Framework’ (without anything SwiftData)
‘Framework’ that uses SwiftData, and optionally links SwiftData
In the Framework, I used ‘#if canImport(X)’, and in the Application, I added ‘SwiftData’ as an optional link.
Now runs on older versions of iOS that don’t support SwiftData.