Hey, happy Monday, none of your Swift code will compile!
Nothing a quick find and replace can’t cure. “Several” protocols have been renamed with the -Type suffix to avoid confusion, say the release notes. “A crapload” may have been a more accurate term but that probably wouldn’t pass Apple QA. Mostly this is a lot clearer – especially with IntegerType, as there were lots of confused beginners wondering why they couldn’t declare an Integer variable.
Unmentioned, but in a similar vein in the opposite direction, various typealiases within protocols have had their Type suffix removed. IndexType, GeneratorType, KeyType, ValueType and SliceType are now just Index, Generator, Key, Value and SubSlice.
This I guess makes up for the extra verbosity of now having to type CollectionType that bugs me a bit, though it will give me a reason to just write “collection” in future articles without always feeling guilty that I haven’t capitalized and monospace-fonted it.
A quick list of small items:
- All the operators declared at the top now have visible precedence levels and associativity, which is handy if you are trying to target the precedence of your own operators.
- Lots of new operators for strides and intervals.
- The weird use of
[T],[K:V]andT?when extendingArray,DictionaryandOptionalis gone, as hasArrayType. Characteris now hashable.- The trend of replacing proxies of C-style things with pointer objects, that started last beta with replacing
CString, continues withUnsafeArrayandUnsafeMutableArraybecomingUnsafeBufferPointerandUnsafeMutableBufferPointer. - The law finally caught up with
Arrayand made it mark its various mutable methods as mutable. Same forContiguousArrayandSlice. - Various integer types have had the
getArrayBoundValuefunction changed to anarrayBoundValueget property. Stringnow has inits that take integers. You can also supply a radix, as well as whether you want digits above 9 to be in upper or lower case.- In addition to
Arrayacquiringfirstandlast, the lazy collections also implementfirst(andlastif they can index bidirectionally), as well asisEmpty. - There’s also a non-member
firstandisEmptythat takes a collection, and alastthat takes a collection if it has a bidirectional iterator. Optionalnow has ahasValueproperty instead of agetLogicValue()function.String.compareis gone.UIntand family’sasSigned()has gone. Instead, usenumericCastwhich appears to have been revamped a bit to do more at compile time.UIntnow has a bitwise initializer from its signed equivalent, which you need to explicitly call with abitPattern:argument.- Relatedly,
reinterpretCasthas been renamedunsafeBitCast. You have been warned. - New
prefixandsuffixfunctions take aSliceableand return the start or end of it as a slice. - You can no longer access the underlying sequences of a
Zip2sequence. - There’s now a version of
assertthat takes aBooleanTypeexpression, not just a bool. - The comment descriptions for
sortnow have a helpful link to wikipedia about strict weak ordering! - The function passed to
withExtendedLifetimeactually takesxas an argument now.
Poor old Range has been thoroughly demoted. One minute it’s on top of the world, then last time stride takes its spot for non-contiguous increments. Now ClosedInterval and HalfOpenInterval replace it for general purpose ranges. They also follow the pattern adopted by StrideTo and StrideThrough of having completely different types for the two kinds, determined at compile time. They require their initializing values to conform to ComparableType, which means they can detect if they are inverted and can efficiently detect overlap between two intervals.
Range is now relegated entirely to managing collection indices. The odd thing about this is that Int, probably the most common thing to use to initialize a range, is also an index type, so Range still gets to come out and play all the time.
By the way, I love how the definitions of StrideTo and StrideThrough have a FIXME in their comments about how they ought to be collections.
Finally, ever wonder why when you declared your class to be a Collection, you got chewed out by the compiler for not implementing _Collection? Well out of the shadows emerges the (newly renamed) _CollectionType. Here you will find the missing bits of what made collections work – startIndex, IndexType etc. Same goes for _Sequence, _IntegerArithmeticType etc. It’s not clear why these aren’t just pulled up into their non-underscore equivalents, but at least now you can go look at them instead of having to reverse-engineer what you needed to implement.
[…] For a nice roundup of Xcode6-beta5 changes, check out the release notes and this handy post. […]
[…] For a nice roundup of Xcode6-beta5 changes, check out the release notes and this handy post. […]
[…] Airspeed Velocity. Great blog about the Swift language (not iOS or OS X programming) that goes over changes with every Beta. Also covers a lot more in depth topics. […]
[…] Airspeed Velocity. Great blog about the Swift language (not iOS or OS X programming) that goes over changes with every Beta. Also covers a lot more in depth topics. […]
[…] Airspeed Velocity. Great blog about the Swift language (not iOS or OS X programming) that goes over changes with every Beta. Also covers a lot more in depth topics. […]
[…] Changes in the Swift Standard Library in Beta 5 […]
[…] since Swift 1.0 beta 5, Range has supposed to be only for representing collection index ranges. If you’re not […]