CoreData + CloudKit compilation problem in iOS 15

I'm trying to validate by app with the latest Xcode 13 RC.

I found out that what was building well on Xcode 12, is not longer compiling on 13 RC.

For example, I started getting:  Cannot find type 'CKRecord' in scope in a class that already has the import CoreData statement.

In iOS 14 I didn't have to import CloudKit. If I add the import CloudKit statement, it compiles fine and runs on a iOS 15 simulator but it no longer works on iOS 14.

I started getting the following runtime error:

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/73F15947-880B-4902-A640-689C139DE4C4/***.app/***

  Reason: image not found

dyld: launch, loading dependent libraries

DYLD_SHARED_CACHE_DIR=/Users/andrei/Library/Developer/CoreSimulator/Caches/dyld/20G95/com.apple.CoreSimulator.SimRuntime.iOS-14-5.18E182

DYLD_ROOT_PATH=/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 14.5.simruntime/Contents/Resources/RuntimeRoot

DYLD_LIBRARY_PATH=/Users/andrei/Library/Developer/Xcode/DerivedData/***-fuozrngfgzmoluasjlbqzfiahbvg/Build/Products/Debug-iphonesimulator:/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 14.5.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/introspection

DYLD_INSERT_LIBRARIES=/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 14.5.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libBacktraceRecording.dylib:/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 14.5.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libMainThreadChecker.dylib:/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 14.5.simruntime/Contents/Resources/RuntimeRoot/Developer/Library/PrivateFrameworks/DTDDISupport.fram

Any ideas?

you need to import CloudKit for CKRecord. I hit a few of these as well, seems like Xcode 12 had some implicit imports. Just make the imports explicit, and you're good to go.

That's exactly what I did, and it fixed the compilation problems. But to make sure what I'm fixing for iOS15 doesn't break iOS14, I installed iOS14.5 runtime in Xcode 13, and that's where the problem occurs.

I can successfully compile the app, but at runtime, the 14.5 simulator crashes 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/29E251FD-B330-4B30-B3B8-22A86C2961A8/***.app/***

  Reason: image not found

(lldb) 

Can you work around the issue by removing this line ?

privateCloudKitContainerOptions.databaseScope = .private

(private is the default anyway)

To use the private database scope, you can work around this issue by deleting the code to set the databaseScope property on the NSPersistentCloudKitContainerOptions object since it is the default value.

To use the public database scope, you can work around this issue with KeyValueCoding:

let options = NSPersistentCloudKitContainerOptions(containerIdentifier: id) options.setValue(1, forKey: "databaseScope") // .public == 1 // options.databaseScope = CKDatabase.Scope.public description.cloudKitContainerOptions = options

CoreData + CloudKit compilation problem in iOS 15
 
 
Q