I have an app on the AppStore that targets iOS 16 and later.
I would like to introduce support for SwiftData for devices running iOS 17 and later, while maintaining support for iOS 16.
Example code:
import Foundation
import SwiftData
@available(iOS 17, *)
@Model
class Person {
var firstName: String
var lastName: String
init(firstName: String, lastName: String) {
self.firstName = firstName
self.lastName = lastName
}
}
The app crashes because of @Model with the following error:
dyld[5910]: Library not loaded: /System/Library/Frameworks/SwiftData.framework/SwiftData
If I comment out @Model the app runs with no errors.
I cannot drop support for iOS 16, but I need to use SwiftData (not CoreData) and limit the functionality to iOS 17 devices.
The below does not work:
#if canImport(SwiftData)
import SwiftData
#endif
I would’ve thought that at runtime when it reads “@available(iOS 17, *)” that it would not continue to what’s after it since it’s running on iOS 16.