Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Xcode 8

You're reading from   Learning Xcode 8 Learn to build iOS Applications with Xcode 8

Arrow left icon
Product type Paperback
Published in Nov 2016
Publisher Packt
ISBN-13 9781785885723
Length 480 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Jak Tiano Jak Tiano
Author Profile Icon Jak Tiano
Jak Tiano
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Preface 1. Starting Your iOS Journey FREE CHAPTER 2. Welcome to Xcode 3. Introduction to Swift 3 4. Using Storyboards, Auto Layout, and Size Classes 5. Taking Advantage of Source Control in Xcode 6. Building Your First iOS App 7. Integrating Multitouch and Gestures 8. Exploring Common iOS Frameworks 9. Working with Core Data 10. Creating a watchOS Companion App 11. Advanced Input Using Sensors 12. Sending Notifications 13. Writing Unit Tests 14. Debugging an iOS Application 15. Optimizing Your App 16. Distributing an iOS App Index

Adding gestures from code


While implementing gestures from the storyboard is a simple and visual way to set up gestures, sometimes you'll need to get into the details and create them purely with code. In this section, we're going to look at how to do just that, by adding a pinch gesture recognizer that allows us to scale our image up and down.

Creating a gesture through code

The first thing we're going to need to do is create a property to hold our gesture. Since the gesture is going to be created outside of initialization, we are going to have to make it an implicitly unwrapped optional value (remember, that is shown with the exclamation mark after the variable name).

Note

Here's a quick refresher on optional values in Swift:

First, there's a standard variable, which must always contain a value:

var view: UIView

Then, there's an optional variable, which may or may not have a value:

var view: UIView?

This means we need to unwrap the value every time we use it, to make sure there is a value inside...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image