Just found out that building an app with the new iOS 15 SDK (Xcode 13 RC) is no longer backward compatible with iOS 14.x targets when using CloudKit.
Steps to reproduce:
New project in Xcode 13 RC (check the Core Data CloudKit options)
Set the iOS deployment target to 14.0
Modify the generated Persistence.swift file and add a private CK store like this:
let cloudStoreDescription = NSPersistentStoreDescription(url: url.appendingPathComponent("(privateCloudStoreName).sqlite")) cloudStoreDescription.configuration = "privateCkStoreName" var privateCloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: "CKIDENTIFIFER") privateCloudKitContainerOptions.databaseScope = .private cloudStoreDescription.cloudKitContainerOptions = privateCloudKitContainerOptions
Run on iPhone with iOS 15 -> will work
Download more simulator runtimes and add iOS 14.5
Run on iPhone with iOS 14.5 -> will fail with:
dyld: Library not loaded: /System/Library/Frameworks/_CoreData_CloudKit.framework/_CoreData_CloudKit Referenced from: /Users/andrei/Library/Developer/CoreSimulator/Devices/8554B734-4894-4DD0-A8FA-6C20983F3A49/data/Containers/Bundle/Application/1317D63A-F14B-4EA2-8F18-8EA623D358AB/testapp.app/testapp Reason: image not found
How can I mitigate this since next week iOS 15 will be released to the general public?
Reproducible example here. Feedback assistant id: FB9630276
CodePudding user response:
The solution was in front of my eyes the whole time:
Just remove the following line:
privateCloudKitContainerOptions.databaseScope = .private
Removing that line will have the same effect as the private scope is default and also will remove the need of importing CloudKit.
By doing this, there is no more crash on iOS 14.x
If you want to use the .public scope, according the Apple Frameworks Enginner, the fix is the following:
let options = NSPersistentCloudKitContainerOptions(containerIdentifier: id)
options.setValue(1, forKey: "databaseScope") // .public == 1 // options.databaseScope = CKDatabase.Scope.public
description.cloudKitContainerOptions = options