https://github.com/rxswiftcommunity/rxcloudkit
RxCloudKit (based on RxSwift)
https://github.com/rxswiftcommunity/rxcloudkit
cloudkit ios reactive reactive-extensions reactive-programming rxswift swift
Last synced: 12 months ago
JSON representation
RxCloudKit (based on RxSwift)
- Host: GitHub
- URL: https://github.com/rxswiftcommunity/rxcloudkit
- Owner: RxSwiftCommunity
- License: mit
- Created: 2017-06-22T16:33:56.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-07-02T07:10:22.000Z (almost 7 years ago)
- Last Synced: 2025-04-05T13:51:20.572Z (about 1 year ago)
- Topics: cloudkit, ios, reactive, reactive-extensions, reactive-programming, rxswift, swift
- Language: Swift
- Homepage:
- Size: 83 KB
- Stars: 9
- Watchers: 6
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RxCloudKit is based on RxSwift
Basic usage.
```swift
privateDB.rx.save(record: ckRecord).subscribe { event in
switch event {
case .success(let record):
print("record: ", record)
case .error(let error):
print("Error: ", error)
}
}.disposed(by: disposeBag)
```
"RxCKRecord" class provides syntactic sugar for copying data (including CloudKit metadata) between CKRecord objects and plain structs.
```swift
struct MyRecord {
var myField: String
}
extension MyRecord: RxCKRecord {
static var zone = "MyZone"
static var type = "MyType"
mutating func readUserFields(from record: CKRecord) {
// TODO
}
}
let myRecord = MyRecord(myField: "")
let ckRecord = try! myRecord.asCKRecord()
//
myRecord.read(from: ckRecord)
```
"Cache" class is an out of the box solution for maintaining a local cache of CloudKit records. Tokens are stored in UserDefaults.
```swift
var cache: Cache {
return Cache(delegate: self, zoneIDs: ["MyZone"])
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
application.registerForRemoteNotifications()
self.cache.applicationDidFinishLaunching()
return true
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
self.cache.applicationDidReceiveRemoteNotification(userInfo: userInfo, fetchCompletionHandler: completionHandler)
}
```
```swift
extension AppDelegate: CacheDelegate {
public func cache(record: CKRecord) {
// TODO store record in CoreData
}
public func deleteCache(for recordID: CKRecordID) {
// TODO delete record in CoreData
}
public func deleteCache(in zoneID: CKRecordZoneID) {
// TODO delete everything relevant to zone in CoreData
}
public func query(notification: CKQueryNotification, fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// TODO store/delete record in CoreData
}
}
```
Carthage setup.
```
github "RxSwiftCommunity/RxCloudKit" ~> 1.1.0
```
Copyright (c) RxSwiftCommunity