0

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:

  1. New project in Xcode 13 RC (check the Core Data + CloudKit options)

  2. Set the iOS deployment target to 14.0

  3. 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

  4. Run on iPhone with iOS 15 -> will work

  5. Download more simulator runtimes and add iOS 14.5

  6. 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

Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
Andrei Matei
  • 1,049
  • 2
  • 10
  • 23
  • Ok, at this point I can build with XCODE 13 and run on iOS 15 sim, and build with XCODE 12 and run on iOS 14 sim. How can I distribute a new build to apple this way? – Andrei Matei Sep 16 '21 at 11:01
  • Yes but, according to this the thread: https://developer.apple.com/forums/thread/682925?page=1#687848022 , Apple "made a number of changes to Core Data this year to isolate CloudKit classes from non-cloudkit clients and one of those introduces this new module." Will building against iOS sdk 14 work? Will it pick the new module right from the device: – Andrei Matei Sep 16 '21 at 12:51
  • yes right, I already raised FB9630276. For Stack Overflow is my question around how can I mitigate this problem to avoid crashes once iOS 15 is released to the general public. – Andrei Matei Sep 16 '21 at 14:02
  • no, I tested XCode 12 with iOS 14 simulators -> working, I didn't build Xcode 12 and put the build on iOS 15 simulator. I haven't done that before, maybe it's doable from command line – Andrei Matei Sep 16 '21 at 14:57

1 Answers1

2

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
Andrei Matei
  • 1,049
  • 2
  • 10
  • 23
  • This is truly weird as the .databaseScope is STILL on the [Apple Docs](https://developer.apple.com/documentation/coredata/nspersistentcloudkitcontaineroptions/3580372-databasescope), without any mention of deprecation. – Aviad Ben Dov Aug 20 '22 at 06:35