Update on Swift Language

  1. 5 years ago


    9 Jul 2014 Administrator
    Edited 5 years ago by niutech

    Apple's Xcode 6 beta 3 brings important changes in the Swift programming language:

    • Array in Swift has been completely redesigned to have full value semantics like Dictionary and String have always had in Swift. This resolves various mutability problems – now a ‘let’ array is completely immutable, and a ‘var’ array is completely mutable – composes properly with Dictionary and String, and solves other deeper problems. Value semantics may be surprising if you are used to NSArray or C arrays: a copy of the array now produces a full and independent copy of all of the elements using an efficient lazy copy implementation. This is a major change for Array, and there are still some performance issues to be addressed. Please see the Swift Programming Language for more information.
    • The Array and Dictionary “sugar” syntax has been redesigned: You now declare arrays as [Int] instead of as Int[], as shorthand for Array<Int>. The old syntax made sense when arrays had semantics closer to C arrays, but would be misleading with the new value semantics approach. Along with this, Dictionary syntax has improved so that [Key:Value] is treated as sugar for Dictionary<Key,Value>. Both of these are now consistent with each other and with the literal syntax used to build an array or dictionary. Please see the Swift Programming Language for more information.
    • NSDictionary* is now imported from Objective-C APIs as [NSObject : AnyObject].
    • The half-closed range operator has been changed from .. to ..< to reduce confusion and ambiguity. Now the two range operators are ..< and … for half-closed and closed ranges, respectively (17203527). nil is now a literal in the language, not a global constant of _Nil type. This change resolved a number of problems with nil; e.g. nil in a collection, nil converting to Any, etc. Types can now indicate that they are nil compatible by conforming to the NilLiteralConvertible protocol.
    • APIs imported from C no longer use type aliases like CInt or CFloat, which obfuscated the underlying type. They are now imported as Int32 and Float, etc.
    • APIs imported from C that use C pointers are now imported with a much simpler API type structure which is more predictable, preserves const mutability in more cases, and preserves __autoreleased pointer information. Now you will see UnsafePointer, ConstUnsafePointer, AutoreleasingUnsafePointer, etc. Function pointers are also imported now, and can be referenced and passed around. However, you cannot call a C function pointer or convert a closure to C function pointer type.

    Source: Xcode 6 Beta 3 Release Notes

or Sign Up to reply!