Chapter 6. Web and Search
iOS 9 brings with it some really exciting functionality, such as indexing contents inside your app as searchable content on an iOS device. Even better, you can contribute to iOS’s public search index so that your searchable content appears on devices that don’t even have your app installed. That’s pretty cool, don’t you agree? In this chapter we’ll have a look at all these great features.
6.1 Making Your App’s Content Searchable
Problem
You want the user to be able to search within the contents inside your app, from iOS’s search functionality (see Figure 6-1).
Solution
First construct an object of type CSSearchableItemAttributeSet. This will represent the metadata for any one item that you want to index in the search. Having the metadata, construct an instance of the CSSearchableItem class with your metadata and expiration date, plus some other properties that you will see soon. Index an item using the CSSearchableIndex class. You’ll get a completion block that will let you know whether or not things went well.
Figure 6-1. iOS 9 has improved search functionality
Discussion
You have to keep quite a few things in mind when indexing items in the local device search functionality. I’ll walk you through them one by one. Always keep this index in a useful state. Don’t index stuff that you don’t need, and make sure you delete the old items. You can specify ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access