GithubHelp home page GithubHelp logo

cloudkit-sample-queries's Introduction

CloudKit Samples: Queries

Goals

This project demonstrates use of CloudKit queries against a CloudKit Private Database. It shows how to filter a set of records by using a predicate against a property — in this case, a set of Contact records with a name property, and a BEGINSWITH predicate to query for records prefixed by a user-provided string.

Prerequisites

Setup Steps

  • Ensure the simulator or device you run the project on is signed in to an Apple ID account with iCloud enabled. This can be done in the Settings app.
  • If you wish to run the app on a device, ensure the correct developer team is selected in the “Signing & Capabilities” tab of the Queries app target, and a valid iCloud container is selected under the “iCloud” section.

Using Your Own iCloud Container

  • Create a new iCloud container through Xcode’s “Signing & Capabilities” tab of the Queries app target.
  • Update the containerIdentifier property in Config.swift with your new iCloud container ID.

How It Works

  • On first launch, the app fetches all Contact records from the remote database and displays the names of those records in the UI.
  • When a user adds a new Contact record through the UI, the record is saved to the remote database and the records are retrieved and displayed again.
  • When a user filters the list through the UI, a new query operation is performed using the BEGINSWITH predicate, and only records with the name field beginning with the given filter string are returned and displayed.

Things To Learn

  • How to create new records with the CKModifyRecordsOperation.
  • How to use CKQuery and CKQueryOperation to build a query matching all or specific records, and retrieve and process the results with a recordFetchedBlock.
  • How to use the Result type to provide clear information about the result of asynchronous operations with completion handlers.

Further Reading

cloudkit-sample-queries's People

Contributors

sjrmanning 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.