I have an app where CoreData is working great - but I want to add widgets. I'm following a tutorial where they create an AppGroup and in the migration they use appendingPathComponent(_:) which is deprecated (iOS 8.0–26.1) however the recommended replacement appending(path:directoryHint:) starts support at iOS 16.
I'm hanging on to iOS 15 for some users who don't want to upgrade their phones - but is it time to give up on that for widgets running on released iOS 26 and beyond?
I assume I'll need to use if #available(iOS 16.0, *) for the new code. How does this work for the CoreData migration for the older phones? So far this is just in TestFlight. Any recommendations?
Since this is in your migration code, you'll want to be extra careful that both methods produce the same output that you're expecting.
I'd recommend writing a simple method that encapsulates this:
func append(_ path: String, to url: URL) -> URL {
if #available(iOS 16.0, *) {
url.appending(path: path)
} else {
url.appendingPathComponent(path)
}
}
And testing that it produces the same results when targeting iOS 15 and iOS 16. You might want to double check that both methods handle / characters in the part you're appending in the same way.