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

Commit

Permalink
Add CKContainer variable to config (#20)
Browse files Browse the repository at this point in the history
Squashed commit of the following:
    Update version to 2.0.1
    Revert change: FetchAndSaveOperation.allDatabases
    Fix unit tests crash
    Add `container` variable to config
  • Loading branch information
Sorix committed Feb 3, 2018
1 parent 219194e commit 7b89412
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CloudCore.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "CloudCore"
s.summary = "Framework that enables synchronization between CloudKit (iCloud) and Core Data. Can be used as CloudKit caching mechanism."
s.version = "2.0.0"
s.version = "2.0.1"
s.homepage = "https://github.com/sorix/CloudCore"
s.license = 'MIT'
s.author = { "Vasily Ulianov" => "vasily@me.com" }
Expand Down
10 changes: 5 additions & 5 deletions Source/Classes/CloudCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ open class CloudCore {
#endif

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

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

switch id {
case config.subscriptionIDForPrivateDB: return CKContainer.default().privateCloudDatabase
case config.subscriptionIDForSharedDB: return CKContainer.default().sharedCloudDatabase
case _ where id.hasPrefix(config.publicSubscriptionIDPrefix): return CKContainer.default().publicCloudDatabase
case config.subscriptionIDForPrivateDB: return config.container.privateCloudDatabase
case config.subscriptionIDForSharedDB: return config.container.sharedCloudDatabase
case _ where id.hasPrefix(config.publicSubscriptionIDPrefix): return config.container.publicCloudDatabase
default: return nil
}
}
Expand Down
8 changes: 4 additions & 4 deletions Source/Classes/Fetch/FetchAndSaveOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import CoreData
/// 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`
public class FetchAndSaveOperation: Operation {

/// Private cloud database
/// Private cloud database for the CKContainer specified by CloudCoreConfig
public static let allDatabases = [
// CKContainer.default().publicCloudDatabase,
CKContainer.default().privateCloudDatabase,
// CKContainer.default().sharedCloudDatabase
// CloudCore.config.container.publicCloudDatabase,
CloudCore.config.container.privateCloudDatabase
// CloudCore.config.container.sharedCloudDatabase
]

public typealias NotificationUserInfo = [AnyHashable : Any]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class ObjectToRecordConverter {

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

if serviceAttributes.isPublic { return container.publicCloudDatabase }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CreateCloudCoreZoneOperation: AsynchronousOperation {
self.state = .finished
}

CKContainer.default().privateCloudDatabase.add(recordZoneOperation)
CloudCore.config.container.privateCloudDatabase.add(recordZoneOperation)
self.createZoneOperation = recordZoneOperation
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Classes/Setup Operation/SubscribeOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SubscribeOperation: AsynchronousOperation {
override func main() {
super.main()

let container = CKContainer.default()
let container = CloudCore.config.container

// Subscribe operation
let subcribeToPrivate = self.makeRecordZoneSubscriptionOperation(for: container.privateCloudDatabase, id: CloudCore.config.subscriptionIDForPrivateDB)
Expand Down
7 changes: 7 additions & 0 deletions Source/Model/CloudCoreConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public struct CloudCoreConfig {

// MARK: CloudKit

/// The CKContainer to store CoreData. Set this to a custom container to
/// support sharing data between multiple apps in an App Group (e.g. iOS and macOS).
///
/// Default value is `CKContainer.default()`
// `lazy` is set to eliminate crashes during unit-tests
public lazy var container = CKContainer.default()

/// RecordZone inside private database to store CoreData.
///
/// Default value is `CloudCore`
Expand Down

0 comments on commit 7b89412

Please sign in to comment.