Skip to main content

Stringified selectors are deprecated

About 2 minSwiftArticle(s)bloghackingwithswift.comswiftswift-2.2

Stringified selectors are deprecated 관련

HACKING WITH SWIFT

What's new in Swift?

Stringified selectors are deprecated | Changes in Swift 2.2

Stringified selectors are deprecated

Available from Swift 2.2

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!

Other changes in Swift 2.2…
++ and -- are deprecated | Changes in Swift

++ and -- are deprecated
Traditional C-style for loops are deprecated | Changes in Swift

Traditional C-style for loops are deprecated
Comparing tuples | Changes in Swift

Comparing tuples
Tuple splat syntax is deprecated | Changes in Swift

Tuple splat syntax is deprecated
More keywords can be used as argument labels | Changes in Swift

More keywords can be used as argument labels
Variable parameters have been deprecated | Changes in Swift

Variable parameters have been deprecated
Renamed debug identifiers: line, function, file | Changes in Swift

Renamed debug identifiers: line, function, file
Compile-time Swift version checking | Changes in Swift

Compile-time Swift version checking

Download Swift 2.2 playgroundopen in new window


이찬희 (MarkiiimarK)
Never Stop Learning.