Some highlights from Beta 6:
- A new
try? keyword has been added. This attempts an operation that may throw (fail). If it succeeds the result is wrapped in an optional. If it fails the error is ignored and
nil is returned. This seems like a pragmatic compromise but I have to imagine someone lost a battle somewhere because a lot of programmers are going to slap a
try? on it and ignore all errors.
- Using the
.EnumCase syntax now provides code completions (yay)
- Static computed properties in protocol extensions are now supported
- Variadic parameters can appear anywhere in the parameter list; presumably the compiler disambiguates them by type and/or by consuming values off the right-hand side of argument list until the non-variadic arguments are satisfied. In any case say goodbye to yet another artificial legacy of C.
- Collections of non-Objective-C types are no longer considered
@objc themselves so you'll get a compiler error if you try to force it with
@objc var prop:[SwiftOnlyType]
- Typedefs for block types (
typedef BOOL(^Doer)(void)) now import as Swift type aliases for closures. The release notes under-sell this by claiming it primarily allows
BOOL to import as
Bool instead of
ObjCBool. The bigger benefit in my mind is human-readable type information on the Swift side. I prefer to create aliases for my block types to note the purpose of the block, e.g.
FlagChangedBlock even though both may be
void(^)(BOOL) because it makes the code more self-documenting. Now that work carries over into Swift.
- Error messages produced by the type checker "continue to improve". If a type alias is involved the compiler will now helpfully include the alias and underlying type.
- Lots of improvements to
debugPrint(), including making them variadic and allowing you to specify your own terminator (instead of only supporting new line).
extend was renamed
splice was renamed
- Most APIs that take closures or
@autoclosure parameters use
rethrows properly so you can pass throwing methods to
filter, etc. It also allows short-circuiting operators like
?? to work with expressions that throw.
- A big change to collections, sequences, and splicing: All
CollectionTypes are now sliceable and
SequenceType has the notion of
SubSequence to represent some of the values of the parent sequence in the same order. You can customize your own collections (like
ArraySlice) to provide windowed views onto sections of the parent sequence. Using copy-on-write for mutation and you can effectively slice and dice collections for free. There's a lot to unpack here so I suggest checking out the release notes for yourself.
- As part of this,
ArraySlice indices are no longer zero-based; they map directly into the indices of the collection they are slicing. Again, see the release notes for a good example of what was wrong with the old design and how the changes make things better.
- There is a nasty crash bug related to this; see below.
guard at the top level of a file no longer causes memory corruption
- Taking the
inout of an invalid expression no longer crashes the compiler (e.g.
Still Bugs or New Bugs
- Declaring multiple globals in a single
let may cause corruption of their values; the workaround is to declare them with separate
- You still can't extend a Core Foundation type to conform to a protocol; casting to the protocol will fail in optimized builds.
- Array slices with a non-zero lower index are incorrectly displayed in the REPL and LLDB. Playgrounds with them will crash with
If I had to guess, I'd say the next release will be the GM release. There could be one more beta but I am not expecting any further changes. If the rumor mill (and past Septembers) are any guide, we'll see new hardware the second week of September and iOS 9 will GM along with Xcode 7 at the same time.
This blog represents my own personal opinion and is not endorsed by my employer.