O'Reilly logo

Learning Swift, 2nd Edition by Jon Manning, Tim Nugent, Paris Buttfield-Addison

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required