Xcode 7.3 b4, Swift 2.2
February 24, 2016
A new beta means a new compiler. Check out the official release notes for more information.
Swift 2.2
- Lots of compiler crashes have been fixed.
- You can use
#if swift(>=x.y)
checks to gate the use of compiler features. This should finally make it possible to have a single branch support multiple versions of Swift simultaneously (though only going forward) - The
associatedtype
keyword replacestypealias
for associated types. It was always strange to me that the keyword was overloaded for entirely different purposes so this is a very welcome change. The use oftypealias
for associated types will be removed in Swift 3.- This is supposed to apply to adopters of protocols where they want or need to specify the associated type, but currently does not.
- You can get a reference to a function by providing the name including argument labels.The syntax is
someFunc(_:label1:label2:)
. The underscore is a consequence of the rule that un-labelled parameters are specified with an underscore and the first parameter usually doesn't carry a label. This can be useful when there are overloads and it is easier to specify which overload via the labels rather than having to provide a type signature.It is absolutely required when the overloads have the same type signature and only differ by label. - The C-style macro-ish
__FILE__
,__LINE__
,__COLUMN__
, and__FUNCTION__
symbols have been replaced by#file
,#line
,#column
, and#function
. This is definitely more consistent with general Swift style and the general principle when you see#
some compile-time magic is happening.
Objective-C Selectors
- You can get a selector for an Objective-C method with
#selector
. No more stringly-typed selectors! - The old behavior has been deprecated and the compiler will offer fix-its for it.
- There is one caveat: Currently it isn't possible to use this support for property getters so you can construct those using strings.
- If you are thinking the compiler will be really annoying and offer fix-its for cases you can't fix I have good news: Swift parses selector strings and validates that there is in fact an Objective-C selector visible matching the string.
Russ Bishop
This blog represents my own personal opinion and is not endorsed by my employer.