Chapter 14. Polishing the iOS App

Our iOS notes application is now largely feature-complete. It’s fully operational, but could do with a few more finishing touches to add some polish. In this chapter, we’ll add support for opening links in the provided web browser view controller, overall app settings, undo, and image filters.

Opening Links in SFSafariViewController

Links in the text are currently tappable, but this functionality is not ideal, for two reasons:

  • It’s available only when the text view is not editable.

  • Tapping links launches Safari, taking users out of the app. This is probably something they don’t want.

To fix the first problem, we’ll add support for moving between an “editing” mode and a “viewing” mode for the DocumentViewController. To fix the second, we’ll override the existing behavior for opening links, and instead open them in the SFSafariViewController.

There are three ways in which an app can display web content: creating a custom mini-browser by using WKWebView or UIWebView, pushing the user out of the app by opening Safari using openURL, or using SFSafariViewController to display a compact version of Safari within the app.

WKWebView or UIWebView are outside the scope of this book, as these days they’re only necessary if you’re doing something complex with web views, or you’re making your own web browser for iOS (like Chrome, Firefox, Mercury Browser, or similar). In the past, most apps implemented their own custom mini-browser using either UIWebView ...

Get Learning Swift, 2nd Edition 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.