Skip to content

Instantly share code, notes, and snippets.

@lilyball
Created July 8, 2014 00:36
Show Gist options
  • Save lilyball/0928f2474cab04db18f4 to your computer and use it in GitHub Desktop.
Save lilyball/0928f2474cab04db18f4 to your computer and use it in GitHub Desktop.
Summary of Swift stdlib differences from b2 to b3
Interesting differences in the Swift standard library from b2 to b3:
A bunch of internal stuff got tweaked. That's all omitted here.
posix_read() / posix_write() have been deleted. I think the Darwin module's read()/write()/ are the same thing though.
+= operators for ArrayType + rhs have been removed, in favor of operators where the lhs is either Array<T>, ContiguousArray<T>, or Slice<T>. As those are the 3 builtin classes that implement ArrayType, this shouldn't make a difference to anyone. === and !== remain defined in terms of ArrayType.
a..b has been replaced with a..<b.
bridgeFromObjectiveC() returns T instead of T?, new bridgeFromObjectiveCConditional() for T?
Sorting methods (insertionSort/quickSort/sort) and partition() all use RandomAccessIndex now.
new sorted() function. Supports both MutableCollection (returns the collection type) or Sequence (returns an array).
transcode() has a new stopOnError: parameter, with a return value that indicates if an error occurred.
succ() and pred() are nwo successor() and predecessor()
ImplicitlyUnwrappedOptional is now an enum with its own None/Some() cases instead of a struct wrapping Optional
Array has a new function withUnsafeMutableStorage() that provides access to an UnsafeMutableArray value. Also exists on ContiguousArray and Slice. UnsafeMutableArray is a new type that only exists for this function.
uncheckedAdd/Subtract/etc are now called add/subtract/etcWithOverflow()
Range now has a map() method that produces an array
String no longer has an initializer that takes a UnicodeCodec + a Collection.
String.fromCString(up: UnsafePointer<CChar>) -> String is no more
New method String.fromCStringRepairingIllFormedUTF8(cs: CString) -> (String?, hadError: Bool)
UTF16.measure() has new argument repairIllFormedSequences: Bool and an optional return type
UnicodeScalar has separate DebugPrintable definition in addition to its existing Printable
New protocol NilLiteralConvertible for types that can convert from nil
UnicodeCodec protocol declares init() and changes decode() from class to instance func, and changes return value from UnicodeScalar? to the new UTFDecodeResult type. All implementors have changed accordingly.
AutoreleasingUnsafePointer supports subscripting, null-initialization, and initialization from UnsafePointer or ConstUnsafePointer.
CConstPointer/CConstVoidPointer/CMutablePointer/CMutableVoidPointer are all gone. Any conversions to these types from other classes are (of course) gone.
New type CFunctionPointer. No way to actually call anything with it, it's just a pointer type for referring to C function pointers.
New type ConstUnsafePointer<T>. Basically the immutable version of UnsafePointer, except it has a method .withUnsafePointer() that can be used to get an UnsafePointer version (which I guess is the equivalent of casting away const-ness in C).
CString now has an initializer from UnsafePointer<CChar>
Numeric types (e.g. Int) now have endian-specific initializers and property getters.
UnicodeScalar's escape() method has a new parameter #asASCII: Bool
UnsafeArray is no longer a Generator. It behaves like every other Collection and has a generate() method. Documentation comment has not been updated yet and still pretends it's both a collection and a generator. It calls this an experiment; the split may indicate that the experiment is over and that collections and generators will be kept distinct.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment