Swift 2 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 andnilis 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 atry?on it and ignore all errors.
This is a good addition that was suggested last month. I’m not worried about errors being ignored because the compiler warns if the result of try? is unused. It lets you ignore the specific error that you got, but you still have to handle the fact that there was an error.
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.
It looks to me like it’s simpler than that, and you simply use a named parameter to signal the end of the variadic parameter. Perhaps in the future it will be possible to support multiple variadic parameters in this way. For now, the main benefit is that you can more easily use trailing closures.
extendwas renamedappendContentsOfandsplicewas renamedinsertContentsOf
It’s good to see Apple keeping some of Foundation’s good ideas.
Most APIs that take closures or
@autoclosureparameters userethrowsproperly so you can pass throwing methods tomap,filter, etc. It also allows short-circuiting operators like&&,||, or??to work with expressions that throw.
This should make error handling easier than before.
There are still some bugs, though:
Declaring multiple globals in a single
varorletmay cause corruption of their values; the workaround is to declare them with separatevarorletstatements.
You can combine
try?with??for fallback values but you must surround the try in parens[…]
Beta 6 introduces a
lazyproperty on sequences.[…]
This property is implemented in
CollectionType,LazyCollectionType, andLazySequenceTypeextensions. You use it to delay evaluation on things like map and filter that are normally eager.
Joinhas becomejoinWithSeparator, which you call after a sequence, interposing a separator between the elements of a sequence.
1 Comment RSS · Twitter
[…] Swift 2 Beta 6; Up the mix with Beta 6; How to Print: the Beta 6 edition […]