2
votes

Let's say I have several application targets, main one being application itself with all required CloudKit entitlements. Application works fine and fetches data through CloudKit. I have following class that fetches CloudKit databases.

import CloudKit

class Database {

    static let container = CKContainer(identifier: "iCloud.com.identifier")

    static let publicDatabase = {
        return container.publicCloudDatabase
    }

    static let privateDatabase = {
        return container.privateCloudDatabase
    }
}

Now let's say there is a function that retrieves some records from the CloudKit.

public func retrieveData(completion:(CKRecord?) -> () 

Function works fine when used in the application, but when I write unit test for it and I run it, CloudKit container crashes on this line:

static let container = CKContainer(identifier: "iCloud.com.identifier")

with following info:

*** Terminating app due to uncaught exception 'CKException', reason: 'The application is missing required entitlement com.apple.developer.icloud-services'.

Note that I have all required entitlements inside main application target and that they work fine, so I want to know is there any way I can make it work in test target?

1

1 Answers

0
votes

Make sure that all the classes from the main target you use in your test classes also have your Test target set enter image description here