Chapter 13. Address Book

13.0. Introduction

On an iOS device, the Contacts application allows users to add contacts to, remove contacts from, and manipulate their address books. An address book can be a collection of people and groups. Each person can have properties such as first name, last name, phone number, and email address. Some properties can have a single value, and some can have multiple values. For instance, the first name of a person is one value, but the phone number can be multiple values (e.g., if the user has two home phone numbers).

The AddressBook.framework framework in the iOS SDK allows you to interact with the address book database on the device. You can get the array of all entities in the user’s address book, insert and change values, and much more.

To use the address book-related functions in your application using the latest LLVM compiler features, all you have to do is import the following frameworks into your source code:

import UIKit
import AddressBook
import AddressBookUI

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  var window: UIWindow?

}

Note

You can use the Address Book framework on iOS Simulator, and you will be happy to know that Apple has already prepopulated the Contacts database on the simulator so that you don’t have to do that by yourself (see Figure 13-1).

The Contacts app on the simulator already contains prepopulated information
Figure 13-1. The Contacts app on the simulator already contains ...

Get iOS 8 Swift Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.