Re: Anyone using CloudKit?
I've made some progress on mocking by defining a protocol containing the CKDatabase methods I call; an empty extension to mark CKDatabase as implementing that protocol; and a mock class that implements the protocol. Then in my code I just change references to `CKDatabase` to `IndirectCKDatabase`, and allow the instance to be injected. public protocol IndirectCKDatabase : AnyObject { var databaseScope: CKDatabase.Scope { get } func add(_ operation: CKDatabaseOperation) func save(_ record: CKRecord, completionHandler: @escaping (CKRecord?, Error?) -> Void) func delete(withRecordID recordID: CKRecord.ID, completionHandler: @escaping (CKRecord.ID?, Error?) -> Void) } extension CKDatabase : IndirectCKDatabase { } class MockCKDatabase : IndirectCKDatabase { ... } But in implementing the mock class I'm running into roadblocks:
I've been searching for other people's solutions to mocking, and it seems various people have gone down this road, but I haven't found anyone whose gotten farther than I have :( —Jens |
|