iOS 9: Introducing Search APIs

At WWDC 2015, Apple has officially announced iOS 9. In addition to many new features and improvements, this update also gives developers the opportunity to make the content of their apps available. More detection and access via Spotlight search. The new API available in iOS 9 allows you to index any content or status of the interface in your application, making it easy to reach your users through Spotlight. The three components of the new search APIs are:

  • NSUserActivity class, which is designed to view the content of the app.
  • Core Spotlight framework, designed for any content of the app.
  • Web markup, designed for apps that have content that is symmetrical on the website.

In this article, we will show you how you can use the NSUserActivity class and Core Spotlight framework in your application.

This tutorial requires you to be running Xcode 7 on OS X 10.10 or later. To follow along with us, you can also download the starter project from GitHub .

In the first part of this tutorial, I will show you how you can index the content of an application through NSUserActivity classes. This API is one of the similar ones used for Handoff, a feature introduced in iOS 8 last year, and handles both storing and restoring the current state of the application.

If you haven't worked with NSUserActivity , the author suggests you read their tutorial here including Handoff and NSUserActivity before we continue.

Before writing any code, open the starter project and run the app with a virtual machine or a real machine. At this point, you will find that the application simply displays a list of four TV shows and detailed pages for each program.

To start, open the project and open the DetailViewController.swift file. Add the configureView method of the DetailViewController class with the following lines of code:

Share the news now