Chapter 10. Web and Search
iOS 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.
10.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 10-1).
Solution
First, you will need to 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.
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 ...
Get iOS 10 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.