Pass Parameters in Tap Gestures
Also known as stop casting / stop using tags
3 min readNov 10, 2021
Before we start
Difficulty: Beginner | Easy | Normal | Challenging
This article has been developed using Xcode 13.0, and Swift 5.3
Prerequisites
- It will be useful if you are familiar with subclassing in Swift
The video
This project
The answer
If you’ve several UIView
instances in a view and wish to easily identify which is in a UIViewController
. So the end result look something like the following:
Isn’t that nice! There are three different views here and we would like to differentiate between each one when the user taps them. Surely this is an easy task?
Now remember, there isn’t any MVVM or great architecture here so I’ve crammed everything into the ViewController — this article is about the Gestures rather than anything else!