CloudKit, Apple’s remote data storage service, provides a possibility to store app data using users’ iCloud accounts as a back-end storage service.

Overview

CloudKit

CloudKit, Apple’s remote data storage service, provides a possibility to store app data using users’ iCloud accounts as a back-end storage service.

Here is the same demo on Objective-C.

Requirements

  • iOS 8.0+
  • XCode 10.2
  • Swift 5

How To Get Started

  • Set up Cloud/CloudKit at iOS Developer Portal.
  • Insert a bundle identifier and choose a corresponding Team.
  • Select Capabilities tab in the target editor, and then switch ON the iCloud.

For more detailed information take a look at our article.

Usage

Retrieve existing records

let predicate = NSPredicate(value: true)
let query = CKQuery(recordType: recordType, predicate: predicate)
CKContainer.default().publicCloudDatabase.perform(query, inZoneWith: nil) { records, error in

}

Create a new record

let record = CKRecord(recordType: "RecordType")
record.setValue("Some data", forKey: "key")
CKContainer.default().publicCloudDatabase.save(record) { savedRecord, error in

}

Update the record

let recordId = CKRecord.ID(recordName: "RecordType")
CKContainer.default().publicCloudDatabase.fetch(withRecordID: recordId) { updatedRecord, error in  
    if error != nil {
        return
    }

    updatedRecord.setObject("Some data", forKey: "key")
    CKContainer.default().publicCloudDatabase.save(updatedRecord) { savedRecord, error in

    }
}

Remove the record

let recordId = CKRecord.ID(recordName: recordId)
CKContainer.default().publicCloudDatabase.delete(withRecordID: recordId) { deletedRecordId, error in

}

Contacts

Yalantis

Follow Yalantis on Twitter (@Yalantis) and [Facebook] (https://www.facebook.com/Yalantis?ref=ts&fref=ts)

License

The MIT License (MIT)

Copyright © 2017 Yalantis

Permission is hereby granted free of charge to any person obtaining a copy of this software and associated documentation files (the "Software") to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Comments
  • Thanks for the project

    Thanks for the project

    Just wanted to say thanks- this helped me to start learning Cloudkit really quickly. I used the project to build a companion Mac App also leveraging Cloudkit which lets you subscribe to Cloudkit updates and synchronise your city database.

    I have open sourced it here: https://github.com/grantkemp/CloudKit-Demo-OSX

    opened by grantkemp 2
  • DidReceiveRemoteNotificationsStops working after 40 calls?

    DidReceiveRemoteNotificationsStops working after 40 calls?

    Hi - I am not sure if you have tried out my project, but I have discovered a strange issue when pairing up with your app.

    For some reason after the number of entries goes over 40 and If there is an active CKSubscription, then it appears that the remoteNotification is received as the badge number is incremented, however the the Application Delegate method didReceiveRemoteNotifications stops being called

    Any idea how to make it continue to work after 40 entries?

    opened by grantkemp 1
  • Got the Error while fetching data

    Got the Error while fetching data

    I got the error when fetching data from the cloud Couldn't get container configuration from the server for container

    static var privateCloudDatabase: CKDatabase {
         return CKContainer.default().privateCloudDatabase
    }
    
    static func fetchAllStickers(_ userId: String, completion: @escaping (_ success: Bool, _ error: Error?) -> Void) {
         let predicate = NSPredicate(format: "userId = %@", userId)
         let query = CKQuery(recordType: recordType, predicate: predicate)
        
         privateCloudDatabase.perform(query, inZoneWith: nil) { (records, error) in
                for record in records ?? [] {
                    print(record)
                }
            }
            if let e = error {
                print("Error: \(e.localizedDescription)")
    
                DispatchQueue.main.async {
                    completion(false, nil)
                }
            } else {
                DispatchQueue.main.async {
                    completion(true, nil)
                }
            }
         }
     }
    

    Your Environment

    • Swift version: 5.1
    • iOS version: 13.1
    • Device: iPhone 7
    • Xcode version: 11.2.1
    opened by StackHelp 0
  • Enhancement: show flow if the user is not signed into iCloud

    Enhancement: show flow if the user is not signed into iCloud

    Currently if the user is not signed into icloud we should be showing the flow of pointing out to users how to recover and resolve this error. Apple doesn't have a default way to solve this in IOS as far as I can see (unlike on web)

    priority: low status: queued type: enhancement 
    opened by grantkemp 0
  • "our article" link is broken in README.md

    Report

    The README.md file has has a broken link to "our article": https://yalantis.com/blog/work-cloudkit/?utm_source=github

    The link is broken in both Swift and Objective-C versions of GitHub.

    opened by 101airborne 0
Owner
Yalantis
Knowledge is power and the way to get power is by sharing knowledge. We are open source because this is a smart way to live, work and play.
Yalantis
Enables developers to write code that interacts with CloudKit in targets that don't support the CloudKit Framework directly

CloudKit Web Services This package enables developers to write code that interac

Eric Dorphy 3 May 11, 2022
Enables developers to write code that interacts with CloudKit in targets that don't support the CloudKit Framework directly

CloudKit Web Services This package enables developers to write code that interac

Eric Dorphy 2 Dec 27, 2021
Simplified access to Apple's CloudKit

EVCloudKitDao Discuss EVCloudKitDao : What is this With Apple CloudKit, you can focus on your client-side app development and let iCloud eliminate the

Edwin Vermeer 632 Dec 29, 2022
This is the BlurrMC social media platform for iOS hosted on Apple's CloudKit.

BlurrMC for iOS This is the BlurrMC social media platform for IOS! WOOOOOOO! On this version of the social media platform, you have the full featured

BlurrMC 0 Nov 4, 2021
StorageManager - FileManager framework that handels Store, fetch, delete and update files in local storage

StorageManager - FileManager framework that handels Store, fetch, delete and update files in local storage. Requirements iOS 8.0+ / macOS 10.10+ / tvOS

Amr Salman 47 Nov 3, 2022
💾 Safe, statically-typed, store-agnostic key-value storage written in Swift!

Storez ?? Safe, statically-typed, store-agnostic key-value storage Highlights Fully Customizable: Customize the persistence store, the KeyType class,

Kitz 67 Aug 7, 2022
An Objective-C wrapper for RocksDB - A Persistent Key-Value Store for Flash and RAM Storage.

ObjectiveRocks ObjectiveRocks is an Objective-C wrapper of Facebook's RocksDB - A Persistent Key-Value Store for Flash and RAM Storage. Current RocksD

Iskandar Abudiab 56 Nov 5, 2022
Typed key-value storage solution to store Codable types in various persistence layers with few lines of code!

?? Stores A typed key-value storage solution to store Codable types in various persistence layers like User Defaults, File System, Core Data, Keychain

Omar Albeik 94 Dec 31, 2022
CoreDataCloudKitShare - Learn how to use Core Data CloudKit

Sharing Core Data Objects Between iCloud Users Implement the flow to share data

null 3 Feb 10, 2022
Effortlessly synchronize UserDefaults over iCloud.

Zephyr ??️ Effortlessly sync UserDefaults over iCloud About Zephyr synchronizes specific keys and/or all of your UserDefaults over iCloud using NSUbiq

Arthur Ariel Sabintsev 841 Dec 23, 2022
iForage helps foragers to track and manage foraging spots around them using CloudKit

iForage CloudKit Preface To expand on what I've created here: https://github.com/LynchConnor/iForage, I initially developed the app using Firebase. Th

Connor Lynch 3 Jul 14, 2022
Disk is a powerful and simple file management library built with Apple's iOS Data Storage Guidelines in mind

Disk is a powerful and simple file management library built with Apple's iOS Data Storage Guidelines in mind

Saoud Rizwan 3k Jan 3, 2023
Sync Realm Database with CloudKit

IceCream helps you sync Realm Database with CloudKit. It works like magic! Features Realm Database Off-line First Thread Safety Reactive Programming O

Soledad 1.8k Jan 6, 2023
An elegant, fast, thread-safe, multipurpose key-value storage, compatible with all Apple platforms.

KeyValueStorage An elegant, fast, thread-safe, multipurpose key-value storage, compatible with all Apple platforms. Supported Platforms iOS macOS watc

null 3 Aug 21, 2022
🛶Shallows is a generic abstraction layer over lightweight data storage and persistence.

Shallows Shallows is a generic abstraction layer over lightweight data storage and persistence. It provides a Storage<Key, Value> type, instances of w

Oleg Dreyman 620 Dec 3, 2022
Your Data Storage Troubleshooter 🛠

Your Data Storage Troubleshooter ?? Introduction StorageKit is a framework which reduces the complexity of managing a persistent layer. You can easily

StorageKit 231 Dec 29, 2022
Realm-powered Core Data persistent store

RealmIncrementalStore Realm-powered Core Data persistent store Wait, what? I like Realm. Realm's memory-mapped DB blows other databases out of the wat

Eureka 227 Jun 24, 2022
A Library for iOS developers to check newer version of app from the app store

swift-app-update-checker A very simple solution check new version of your application is available on store or not. Example To run the example project

wajeehulhassan 6 May 13, 2022
macOS App for App Store Connect to Improve Processing Efficiency and Enjoy the Party.

Apple Party(苹果派) 一、App 介绍 AppleParty 是三七互娱旗下37手游 iOS 团队研发,实现快速操作 App Store Connect 后台的自动化 macOS 工具。 使用和原理介绍:开源一款苹果 macOS 工具 - AppleParty(苹果派) 支持功能 内购买

37iOSTeam 173 Dec 30, 2022