You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 17, 2018. It is now read-only.
*Detailed documentation is available at [Wiki](https://github.com/Sorix/CloudCore/wiki).*
40
+
## How to help?
41
+
Current version of framework hasn't been deeply tested and may contain errors. If you can test framework, I will be very glad. If you found an error, please post [an issue](https://github.com/Sorix/CloudCore/issues).
42
+
43
+
## Documentation
44
+
Detailed documentation is [available at CocoaDocs](http://cocoadocs.org/docsets/CloudCore/).
41
45
46
+
## Quick start
42
47
1. Enable CloudKit capability for you application:
4. Make first run of your application in development environment, fill example data in Core Data and wait for syncing. CloudCore will create needed CloudKit schemes automatically.
79
84
85
+
## Service attributes
86
+
CloudCore stores service CloudKit information in managed objects, you need to add that attributes to your Core Data model. If required attributes are not found in entity that entity won't be synced.
87
+
88
+
Required attributes for each synced entity:
89
+
1.*Record Data* attribute with `Binary` type
90
+
2.*Record ID* attribute with `String` type
91
+
92
+
You may specify attribute's names in 2 ways (you may combine that ways in different entities).
93
+
94
+
### User Info
95
+
First off CloudCore try to search attributes by analyzing User Info at your model, you may specify attribute's key as `CloudCoreType` to mark that attribute as service one. Values are:
96
+
**Record Data* value is `recordData`.
97
+
**Record ID* value is `recordID`.
98
+
99
+

100
+
101
+
### Default names
102
+
The most simple way is to name attributes with default names because you don't need to specify User Info. Default names are configured at [[configuration struct|Configuration]], if you haven't changed them it will be `recordID` and `recordData`.
103
+
104
+
Remember that User Info always have a priority, so if User Info is founded for that attribute type it will be used instead of default naming.
105
+
106
+
### 💡 Tips
107
+
* You can name attribute as you want, value of User Info is not changed (you can create attribute `myid` with User Info: `CloudCoreType: recordID`)
108
+
* I recommend to mark *Record ID* attribute as `Indexed`, that can speed up updates in big databases.
109
+
**Record Data* attribute is used to store archived version of `CKRecord` with system fields only (like timestamps, tokens), so don't worry about size, no real data will be stored here.
110
+
80
111
## Example application
81
112
82
113
You can find example application at [Example](/Example/) directory.
@@ -100,4 +131,4 @@ You can find example application at [Example](/Example/) directory.
Copy file name to clipboardExpand all lines: Sources/Classes/CloudCore.swift
+81-23Lines changed: 81 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -9,16 +9,69 @@
9
9
import CoreData
10
10
import CloudKit
11
11
12
+
/**
13
+
Main framework class, in most cases you will use only methods from that class, all methods/properties are static.
14
+
15
+
## Save to cloud
16
+
On application inialization call `observeCoreDataChanges` method, so framework will automatically monitor changes at Core Data and upload it to iCloud.
Updated objects from Core Data can be fetched with `CloudCore.fetchAndSave` methods. If you have called any of CloudCore methods before, CloudCore has automatically subscribed to hidden push notifications about data changes in CloudKit, so after you receive remoteNotifications about that changes, please call appropriate method to redirect that notification to CloudCore and framework will sync data for you.
32
+
33
+
If you want you can sync use force sync method.
34
+
35
+
Please use method with notification user info parameter if you're calling it from `didReceiveRemoteNotification`, because CloudCore extracts CloudKit database from notification to make less network requests on fetching.
/// CloudCore configuration, it's recommended to set up before calling any of CloudCore methods. You can read more at `CloudCoreConfig` struct description
15
58
publicstaticvarconfig=CloudCoreConfig()
59
+
60
+
/// `Tokens` object, read more at class description. By default variable is loaded from User Defaults.
/// Enable observing of changes at local database and saving them to iCloud
21
-
/// - note: if that method was never called before it automaticly invokes `FetchAndSave` operation to load initial data from CloudKit
65
+
// MARK: Save to cloud
66
+
67
+
/** Enable observing of changes at local database and saving them to iCloud
68
+
69
+
**Note**: If that method was never called before it automaticly invokes `fetchAndSave` method to load initial data from CloudKit
70
+
71
+
- Parameters:
72
+
- persistentContainer: contextes without parents will be observed in that container, because saving of that context results writing information to disk or memory
73
+
- errorDelegate: all errors that were occurred during upload processes will be reported to `errorDelegat`e and will contain `Error` or `CloudCoreError` objects.
/// Fetch changes from CloudKit database and save it to CoreData
41
-
///
42
-
/// - Parameters:
43
-
/// - userInfo: notification's user info
44
-
/// - error: block will be called every time when error occurs during process
45
-
/// - completion: called after operation completion
46
-
/// - fetchResult: `FetchResult` enumeration with results of operation. Can be converted to `UIBackgroundFetchResult` to use in background fetch completion calls.
47
-
/// * .noData: if notification doesn't contain CloudCore's data, no fetching was done
48
-
/// * .failed: if any errors have occured during process that status will be set
49
-
/// * .newData: if data is fetched and saved successfully
93
+
// MARK: Fetch from cloud
94
+
95
+
/** Fetch changes from one CloudKit database and save it to CoreData
96
+
97
+
Don't forget to check notification's userinfo by calling `isCloudCoreNotification(withUserInfo:)` before calling that method. If incorrect user info is provided `FetchResult.noData` will be returned at completion block.
98
+
99
+
- Parameters:
100
+
- userInfo: notification's user info, CloudKit database will be extraced from that notification
101
+
- container: `NSPersistentContainer` that will be used to save fetched data
102
+
- error: block will be called every time when error occurs during process
103
+
- completion: `FetchResult` enumeration with results of operation
Copy file name to clipboardExpand all lines: Sources/Classes/Fetch/FetchAndSaveOperation.swift
+10-1Lines changed: 10 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,7 @@
9
9
import CloudKit
10
10
import CoreData
11
11
12
+
/// 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`
12
13
publicclassFetchAndSaveOperation:Operation{
13
14
14
15
privatestaticletallDatabases=[
@@ -29,6 +30,12 @@ public class FetchAndSaveOperation: Operation {
29
30
privateletfetchOperationQueue=OperationQueue()
30
31
privateletcoreDataOperationQueue=OperationQueue()
31
32
33
+
/// Initialize operation, it's recommended to set `errorBlock`
34
+
///
35
+
/// - Parameters:
36
+
/// - databases: list of databases to fetch data from (now supported: private and shared)
37
+
/// - persistentContainer: `NSPersistentContainer` that will be used to save data
38
+
/// - tokens: previously saved `Tokens`, you can generate new ones if you want to fetch all data
Copy file name to clipboardExpand all lines: Sources/Classes/Fetch/PublicSubscriptions/PublicDatabaseSubscriptions.swift
+7-5Lines changed: 7 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -8,22 +8,24 @@
8
8
9
9
import CloudKit
10
10
11
+
// TODO: Temporarily disabled, in development
12
+
11
13
/// Use that class to manage subscriptions to public CloudKit database.
12
14
/// If you want to sync some records with public database you need to subsrcibe for notifications on that changes to enable iCloud -> Local database syncing.
/// Create `CKQuerySubscription` for public database, use it if you want to enable syncing public iCloud -> Core Data
21
23
///
22
24
/// - Parameters:
23
25
/// - recordType: The string that identifies the type of records to track. You are responsible for naming your app’s record types. This parameter must not be empty string.
24
26
/// - predicate: The matching criteria to apply to the records. This parameter must not be nil. For information about the operators that are supported in search predicates, see the discussion in [CKQuery](apple-reference-documentation://hsDjQFvil9).
25
27
/// - completion: returns subscriptionID and error upon operation completion
0 commit comments