Skip to content
This repository was archived by the owner on Dec 17, 2018. It is now read-only.

Commit 7b89412

Browse files
committed
Add CKContainer variable to config (#20)
Squashed commit of the following: Update version to 2.0.1 Revert change: FetchAndSaveOperation.allDatabases Fix unit tests crash Add `container` variable to config
1 parent 219194e commit 7b89412

File tree

7 files changed

+20
-13
lines changed

7 files changed

+20
-13
lines changed

CloudCore.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.name = "CloudCore"
33
s.summary = "Framework that enables synchronization between CloudKit (iCloud) and Core Data. Can be used as CloudKit caching mechanism."
4-
s.version = "2.0.0"
4+
s.version = "2.0.1"
55
s.homepage = "https://github.com/sorix/CloudCore"
66
s.license = 'MIT'
77
s.author = { "Vasily Ulianov" => "[email protected]" }

Source/Classes/CloudCore.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ open class CloudCore {
9191
#endif
9292

9393
// Fetch updated data (e.g. push notifications weren't received)
94-
let updateFromCloudOperation = FetchAndSaveOperation(persistentContainer: container)
94+
let updateFromCloudOperation = FetchAndSaveOperation(persistentContainer: container)
9595
updateFromCloudOperation.errorBlock = {
9696
self.delegate?.error(error: $0, module: .some(.fetchFromCloud))
9797
}
@@ -153,7 +153,7 @@ open class CloudCore {
153153
- completion: `FetchResult` enumeration with results of operation
154154
*/
155155
public static func fetchAndSave(to container: NSPersistentContainer, error: ErrorBlock?, completion: (() -> Void)?) {
156-
let operation = FetchAndSaveOperation(persistentContainer: container)
156+
let operation = FetchAndSaveOperation(persistentContainer: container)
157157
operation.errorBlock = error
158158
operation.completionBlock = completion
159159

@@ -176,9 +176,9 @@ open class CloudCore {
176176
guard let id = notification.subscriptionID else { return nil }
177177

178178
switch id {
179-
case config.subscriptionIDForPrivateDB: return CKContainer.default().privateCloudDatabase
180-
case config.subscriptionIDForSharedDB: return CKContainer.default().sharedCloudDatabase
181-
case _ where id.hasPrefix(config.publicSubscriptionIDPrefix): return CKContainer.default().publicCloudDatabase
179+
case config.subscriptionIDForPrivateDB: return config.container.privateCloudDatabase
180+
case config.subscriptionIDForSharedDB: return config.container.sharedCloudDatabase
181+
case _ where id.hasPrefix(config.publicSubscriptionIDPrefix): return config.container.publicCloudDatabase
182182
default: return nil
183183
}
184184
}

Source/Classes/Fetch/FetchAndSaveOperation.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import CoreData
1212
/// An operation that fetches data from CloudKit and saves it to Core Data, you can use it without calling `CloudCore.fetchAndSave` methods if you application relies on `Operation`
1313
public class FetchAndSaveOperation: Operation {
1414

15-
/// Private cloud database
15+
/// Private cloud database for the CKContainer specified by CloudCoreConfig
1616
public static let allDatabases = [
17-
// CKContainer.default().publicCloudDatabase,
18-
CKContainer.default().privateCloudDatabase,
19-
// CKContainer.default().sharedCloudDatabase
17+
// CloudCore.config.container.publicCloudDatabase,
18+
CloudCore.config.container.privateCloudDatabase
19+
// CloudCore.config.container.sharedCloudDatabase
2020
]
2121

2222
public typealias NotificationUserInfo = [AnyHashable : Any]

Source/Classes/Save/ObjectToRecord/ObjectToRecordConverter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class ObjectToRecordConverter {
120120

121121
/// Get appropriate database for modify operations
122122
private func database(for recordID: CKRecordID, serviceAttributes: ServiceAttributeNames) -> CKDatabase {
123-
let container = CKContainer.default()
123+
let container = CloudCore.config.container
124124

125125
if serviceAttributes.isPublic { return container.publicCloudDatabase }
126126

Source/Classes/Setup Operation/CreateCloudCoreZoneOperation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class CreateCloudCoreZoneOperation: AsynchronousOperation {
2727
self.state = .finished
2828
}
2929

30-
CKContainer.default().privateCloudDatabase.add(recordZoneOperation)
30+
CloudCore.config.container.privateCloudDatabase.add(recordZoneOperation)
3131
self.createZoneOperation = recordZoneOperation
3232
}
3333

Source/Classes/Setup Operation/SubscribeOperation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class SubscribeOperation: AsynchronousOperation {
2020
override func main() {
2121
super.main()
2222

23-
let container = CKContainer.default()
23+
let container = CloudCore.config.container
2424

2525
// Subscribe operation
2626
let subcribeToPrivate = self.makeRecordZoneSubscriptionOperation(for: container.privateCloudDatabase, id: CloudCore.config.subscriptionIDForPrivateDB)

Source/Model/CloudCoreConfig.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ public struct CloudCoreConfig {
2727

2828
// MARK: CloudKit
2929

30+
/// The CKContainer to store CoreData. Set this to a custom container to
31+
/// support sharing data between multiple apps in an App Group (e.g. iOS and macOS).
32+
///
33+
/// Default value is `CKContainer.default()`
34+
// `lazy` is set to eliminate crashes during unit-tests
35+
public lazy var container = CKContainer.default()
36+
3037
/// RecordZone inside private database to store CoreData.
3138
///
3239
/// Default value is `CloudCore`

0 commit comments

Comments
 (0)