Bruce Wade

OS X App Development with CloudKit and Swift

Bruce Wade

Suite No. 1408, North Vancouver, British Columbia, Canada

Any source code or other supplementary materials referenced by the author in this text is available to readers at www.apress.com . For detailed information about how to locate your book’s source code, go to www.apress.com/source-code/ .

ISBN 978-1-4842-1879-2

e-ISBN 978-1-4842-1880-8

DOI 10.1007/978-1-4842-1880-8

Library of Congress Control Number: 2016941345

© Bruce Wade 2016

OS X App Development with CloudKit and Swift

Managing Director: Welmoed Spahr

Lead Editor: Louise Corrigan

Development Editor: James Markham

Technical Reviewer: Charlie Cruz

Editorial Board: Steve Anglin, Pramila Balen, Louise Corrigan, James DeWolf, Jonathan Gennick, Robert Hutchinson, Celestin Suresh John, Nikhil Karkal, Michelle Lowman, James Markham, Susan McDermott, Matthew Moodie, Jeffrey Pepper, Douglas Pundick, Ben Renow-Clarke, Gwenan Spearing

Coordinating Editor: Nancy Chen

Copy Editor: April Rondeau

Compositor: SPi Global

Indexer: SPi Global

For information on translations, please e-mail [email protected] , or visit www.apress.com .

Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at www.apress.com/bulk-sales .

Standard Apress

Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.

While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.

Printed on acid-free paper

Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.springer.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.

Introduction

Over the years, applications have required more and more data that couldn’t possibly fit onto a single computer. Not only that, but with mobile devices developers needed to find a way to ensure the same data can be shared between all devices. Apple also saw this need and invented CloudKit, which allows data storage to be infinitely scaled to meet user demand. CloudKit also works across all Apple products, and Apple even recently opened up JavaScript APIs that allow us to develop web applications that access the same data as our desktop, TvOS, and iOS devices.

In this book we are going to work through creating an OS X application from prototype to fully functional, data-driven app using CloudKit. When you are finished with this book you will be able to leverage CloudKit for your own OS X or iOS applications. We will not be covering iOS development in this book; however, the APIs you use for OS X and iOS are identical.

How This Book Is Organized

Chapter 1 : Introduction

This will provide an overview of this book, what software is required, what you are expected to know, and an overview of what we will be creating.

Chapter 2 : Prototyping Our App

In this chapter we will really start to dive into the planning of our dog parks app. We will primarily be using Sketch 3 in this chapter; however, we will also learn how to use Keynote for basic animations to get a feel for our app before we start coding or even open Xcode.

Chapter 3 : Figuring Out What Data We Need to Store

In this chapter we will take a closer look at our prototype from the previous chapter to dissect what data we really need in order to turn this prototype into a data-driven application. We will also determine which data should be public and which should be private for only your eyes.

Chapter 4 : Introduction to CloudKit

In this chapter we are going to be taking a closer look at CloudKit and how it works. We will cover user authentication, public and private databases, record types, security roles, subscription types, and zones. While we cover these topics we will be taking a closer look at the CloudKit dashboard.

Chapter 5 : Creating Test Data with CloudKit Dashboard

In this chapter we will start adding test data that we will use to display in a working app in subsequent chapters. We will cover how to create public data and how to edit and delete data through the dashboard.

Chapter 6 : Making Our Prototype More Real

Finally, in this chapter we will start migrating our prototype to Xcode so we can have a working app. We will only write enough code to handle authentication and retrieving and displaying our test data in our running app.

Chapter 7 : Updating CloudKit Data from Our App

In chapter 5 we learned how to create/edit/delete data using the CloudKit dashboard. In this chapter we will learn how to update our test data from our app. Then we will implement security roles so users cannot edit data that they have not created themselves.

Chapter 8 : Adding Local Cache to Improve Performance

Finally, in this last chapter we will look at improving performance using a local cache of our data. This will both save server resources and allow the basics of the app to still work, even when there are network connectivity issues.

Contents

  1. Chapter 1:​ Introduction
    1. Goals of This book
    2. Assumptions about the Reader
    3. Software Requirements
      1. Downloading Sketch 3
      2. Downloading and Installing Keynote
      3. Downloading and Installing Xcode
    4. About the App We Are Going to Be Creating
    5. Conclusion
  2. Chapter 2:​ Prototyping Our App
    1. Introduction to Sketch 3
    2. Our Prototype Objective
    3. Building the Prototype with Sketch 3
      1. Creating the Structure of the Main Window
      2. Creating the New Park Button
      3. Creating the Search Field
      4. Creating the Park List
      5. Creating a New Group
      6. Creating Another Main Content Area
    4. Making the Prototype More Real
    5. Reviewing the Features We Want to Display Using KeyNote
      1. Searching for a Park
      2. Adding a New Park
      3. Exporting Artboards to Use Inside KeyNote
      4. Using KeyNote to Make a Realistic Demo
    6. Conclusion
  3. Chapter 3:​ Defining Our Data
    1. Taking a Closer Look at Our Mockup
    2. Dog Park Data Types
    3. Creating Our Project in Xcode
    4. Update the Main.​storyboard
    5. Creating the Left Sidebar
    6. Fixing the App’s Colors to Match Our Mockup
    7. Adding the Search Box
    8. Implementing the Parks List
    9. Setting Up the Detail View
    10. Fixing the Collection View Item
    11. Conclusion
  4. Chapter 4:​ Introduction to CloudKit
    1. iCloud Accounts
    2. Containers
    3. Databases
    4. Records
      1. Record Zones
      2. Record Identifiers
    5. References
    6. Assets
    7. Convenience API
    8. Queries
    9. Subscriptions
    10. CloudKit User Accounts
    11. CloudKit Dashboard
    12. Schema Record Types
    13. Security Roles
    14. Subscription Types
    15. Public Data User Records
    16. Default Zone
    17. Usage
    18. Private Data Default Zone
    19. Admin Team
    20. API Access
    21. Deployment
    22. Conclusion
  5. Chapter 5:​ Creating Test Data with CloudKit Dashboard
    1. Setting Up Our Project for CloudKit
    2. Goals of Test Data
    3. Creating the Parks Record Type
    4. Creating the ParkImages Record Type
    5. Security Role
    6. Create Parks Test Data
    7. Create ParkImages Test Data
    8. Conclusion
  6. Chapter 6:​ Refining Our Prototype
    1. Creating the Park Model
    2. CloudKit API
    3. Populating ParkListViewCont​roller
    4. Setting Up Bindings
    5. Downloading the Thumbnail Asset
    6. Handling Selecting a Park in the List
    7. Update DetailViewContro​ller
    8. Downloading Park Images for the Selected Park
    9. Conclusion
  7. Chapter 7:​ Updating CloudKit Data from Our App
    1. Updating Existing Data
    2. Creating New Data
    3. Deleting a Park
    4. Deleting Park Images
    5. Make the Search Feature Functional
    6. Conclusion
  8. Chapter 8:​ Adding Local Cache to Improve Performance
    1. Caching Park Records
    2. Caching and Loading Park Thumbnails
    3. Caching the Park Images
    4. Additional Suggested Updates
    5. Conclusion
  9. Index

About the Author and About the Technical Reviewer

About the Author

A385012_1_En_BookFrontmatter_Figb_HTML.jpg

Bruce Wade is a software engineer from British Columbia, Canada. He started in software development when he was sixteen years old by coding his first website. He went on to study computer information systems at DeVry Institute of Technology in Calgary. To further enhance his skills, he studied visual and game programming at The Art Institute Vancouver. Over the years he has worked for large corporations as well as several startups. His software experience has led him to utilize many different technologies, including C/C++, Python, Objective-C, Swift, Postgres, and JavaScript. In 2012 he started the company Warply Designed to focus on mobile 2D/3D and OS X development. Aside from hacking out new ideas, he enjoys spending time hiking with his boxer Rasco, working out, and exploring new adventures.

About the Technical Reviewer

A385012_1_En_BookFrontmatter_Figc_HTML.jpg

Charles Cruz is a mobile application developer for the iOS, Windows Phone, and Android platforms. He graduated from Stanford University with B.S. and M.S. degrees in engineering. He lives in Southern California and runs a photography business with his wife ( www.bellalentestudios.com ). When not doing technical things, he plays lead guitar in an original metal band ( www.taintedsociety.com ). Charles can be reached at [email protected] and @CodingNPicking on Twitter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset