One unwelcome quirk of Swift before 2.2 was that selectors could be written as strings, like this:
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Tap!", style: .Plain, target: self, action: "buttonTaped")
If you look closely, I wrote "buttonTaped"
rather than "buttonTapped"
, but Xcode wasn't able to notify me of my mistake if either of those methods didn't exist.
This has been resolved as of Swift 2.2: using strings for selectors has been deprecated, and you should now write #selector(buttonTapped)
in that code above. If the buttonTapped()
method doesn't exist, you'll get a compile error – another whole class of bugs eliminated at compile time!
GO FURTHER, FASTER Unleash your full potential as a Swift developer with the all-new Swift Career Accelerator: the most comprehensive, career-transforming learning resource ever created for iOS development. Whether you’re just starting out, looking to land your first job, or aiming to become a lead developer, this program offers everything you need to level up – from mastering Swift’s latest features to conquering interview questions and building robust portfolios.
Download all Swift 2.2 changes as a playground Link to Swift 2.2 changes
Link copied to your pasteboard.