Swift version: 5.1
Selectors are effectively the names of methods on an object or struct, and they are used to execute some code at runtime. They were common in Objective-C, but the earliest versions of Swift didn't include some core selector functionality so their use declined for a while. That functionality (things like
performSelector(inBackground:)) has since been restored.
In Swift, selectors are most commonly found when working with the target/action paradigm that you find in classes such as
UIBarButtonItem. For example, when you create a timer you need to tell it who to notify when the timer fires (the target) and what selector should be called (the action). The same goes for bar button items: when the button is tapped, what selector should be called, and on what object?
LEARN SWIFTUI FOR FREE I have a massive, free SwiftUI video collection on YouTube teaching you how to build complete apps with SwiftUI – check it out!
Available from iOS 7.0
This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.