Swift 2, Beta 2
June 23, 2015
A quick recap for those who haven't parsed the release notes yet:
- Enum cases with values can be used as a function; basically the compiler automatically creates a function that accepts parameters matching the case's values and returns that enum case with the values filled in.
- Non-mutating methods of structs, enums, and protocols can be partially applied to their
selfparameter. This is just a fancy way of saying if you pass
Type.methodyou'll get the uncurried implementation that needs an instance to operate on and if you pass
instance.methodyou'll get the curried implementation that has
selffilled-in. This already worked for reference types but value types are trickier which is why the non-mutating requirement is there.
- Initializers can be grabbed as a property on the type, e.g.:
String.init. You can still omit it when creating a new value, but if you want to treat
initas a function you can pass around or if you want to
inita type object you'll need to use it explicitly.
- You can grab a reference to a generic parameter's instance methods just like any reference type, so
func smash<A: SomeProtocol>now works.
These are all things that let you access various parts of Swift as if they were standard functions which is a nice win for consistency.
- The Swift compiler has assertions enabled so crash reports should be more useful; not sure why this wasn't part of the first beta.
- Various crashes at compile time and runtime were fixed
- Extensions to generic types can add constraints on the type parameter in the declaration of the extension itself which is a nice simplification
- Overriding an Objective-C method in a way that can't be represented in Objective-C now produces a diagnostic (👍🏻)
- It looks like Protocol metatypes are workable now but I have yet to confirm this.
Loading, Please Wait...
indirectenums haven't landed yet (this is the new feature that lets an enum case contain a value that is the enum itself)
- Extending a CF type to conform to a protocol will fail or crash at runtime in optimized builds
guarddoesn't bind variable names at the top level (a Playground, main, etc) so the values bound in the conditional check don't appear beyond the
guardlike they should
Some handy changes in Beta 2 but I wouldn't expect much response to WWDC feedback and bug reports until the Beta 3-4 timeframe.
Up next: SIMD and Swift
This blog represents my own personal opinion and is not endorsed by my employer.