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
,Dictionary
andOptional
is gone, as hasArrayType
. Character
is now hashable.- The trend of replacing proxies of C-style things with pointer objects, that started last beta with replacing
CString
, continues withUnsafeArray
andUnsafeMutableArray
becomingUnsafeBufferPointer
andUnsafeMutableBufferPointer
. - The law finally caught up with
Array
and made it mark its various mutable methods as mutable. Same forContiguousArray
andSlice
. - Various integer types have had the
getArrayBoundValue
function changed to anarrayBoundValue
get property. String
now 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
Array
acquiringfirst
andlast
, the lazy collections also implementfirst
(andlast
if they can index bidirectionally), as well asisEmpty
. - There’s also a non-member
first
andisEmpty
that takes a collection, and alast
that takes a collection if it has a bidirectional iterator. Optional
now has ahasValue
property instead of agetLogicValue()
function.String.compare
is gone.UInt
and family’sasSigned()
has gone. Instead, usenumericCast
which appears to have been revamped a bit to do more at compile time.UInt
now has a bitwise initializer from its signed equivalent, which you need to explicitly call with abitPattern:
argument.- Relatedly,
reinterpretCast
has been renamedunsafeBitCast
. You have been warned. - New
prefix
andsuffix
functions take aSliceable
and return the start or end of it as a slice. - You can no longer access the underlying sequences of a
Zip2
sequence. - There’s now a version of
assert
that takes aBooleanType
expression, not just a bool. - The comment descriptions for
sort
now have a helpful link to wikipedia about strict weak ordering! - The function passed to
withExtendedLifetime
actually takesx
as 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 […]