GithubHelp home page GithubHelp logo

opencloudkit's Introduction

OpenCloudKit

An open source framework for CloudKit written in Swift and inspired by Apple's CloudKit framework. OpenCloudKit is backed by CloudKit Web Services and is designed to allow easy CloudKit integration into Swift Servers whilst being familiar for developers who have experience with CloudKit on Apple's platforms.

Features

  • Fully featured wrapper around CloudKit Web Services
  • Same API as Apple's CloudKit
  • Supports all major operations supported by Apple’s CloudKit Framework
  • Server-to-Server Key Auth Support

Installation

Swift Package Manager

Add the following to dependencies in your Package.swift.

.Package(url: "https://github.com/BennyKJohnson/OpenCloudKit.git", majorVersion: 0, minor: 5)

Or create the 'Package.swift' file for your project and add the following:

import PackageDescription

let package = Package(
	dependencies: [
		.Package(url: "https://github.com/BennyKJohnson/OpenCloudKit.git", majorVersion: 0, minor: 5),
	]
)

Getting Started

Configure OpenCloudKit

Configuring OpenCloudKit is similar to configuring CloudKitJS. Use the CloudKit.shared.configure(with: CKConfig) method to config OpenCloudKit with a CKConfig instance.

JSON configuration file

You can store CloudKit configuration in a JSON file

// API Token Config
{
    "containers": [{
        "containerIdentifier": "[insert your container ID here]",
        "apiTokenAuth": {
            "apiToken": "[insert your API token and other authentication properties here]"
      },
        "environment": "development"
    }]
}

// Server-to-Server Config
{
    "containers": [{
        "containerIdentifier": "[Container ID]",
        "serverToServerKeyAuth": {
            "keyID": "[Key ID]",
            "privateKeyFile":"eckey.pem"
      },
        "environment": "development"
    }]
}

Initialize a CKConfig from JSON file, OpenCloudKit supports the same structure as CloudKit JS

let config = CKConfig(contentsOfFile: "config.json")

Manual Configuration

Below is an example of building a CKConfig manually

let serverKeyAuth = CKServerToServerKeyAuth(keyID: "[KEY ID]",privateKeyFile: "eckey.pem")
let defaultContainerConfig = CKContainerConfig(containerIdentifier: "[CONTAINER ID]", environment: .development, serverToServerKeyAuth: serverKeyAuth)
let config = CKConfig(containers: [defaultContainerConfig])

CloudKit.shared.configure(with: config)

Working with OpenCloudKit

Get the database in your app’s default container

let container = CKContainer.default()
let database = container.publicCloudDatabase

Creating a record

let movieRecord = CKRecord(recordType: "Movie")
movieRecord["title"] = "Finding Dory"
movieRecord["directors"] = NSArray(array: ["Andrew Stanton", "Angus MacLane"])

Saving a record

database.save(record: movieRecord) { (movieRecord, error) in
    if let savedRecord = movieRecord {
        // Insert Successfully saved record code

    } else if let error = error {
        // Insert error handling
    }
}

opencloudkit's People

Contributors

bennykjohnson avatar tdeleon-tekna avatar malhal avatar

Watchers

Thomas De Leon avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.