Some highlights.
Print and println now produce gutter results
Coalescing is now available:
Interesting results when you use optionals on both sides of the ?? even though this is theoretically an error (“takes an optional on the left and a lazily-evaluated non-optional expression on the right.”)
You can now compare optionals to nil with == and != even if the underlying element doesn’t conform to Equatable. This applies across all optionals. Similarly, Optionals are no longer BooleanType conforming, so you can’t say if (optional). Instead, use if (optional == nil) or if (optional != nil).
The unwrapping operator (!) can be used in assignments, or “assigned through” with mutating methods and operators: The release notes mention that “properties that are optional as a result of lookup through AnyObject cannot be mutated yet.”
Note that in practice these seem to be a little flaky in my tests.
Conformance Audits. UIView, NSView, UIFont, UIApplicationDelegate “have been audited for optional conformance, removing most implicitly unwrapped optionals from their interfaces.” Still lingering issues in other classes but the “changes in Beta 5 are simply the first step; more refinements to the SDK will come in future betas.”
Operators. Some big changes here. What was “operator prefix”, for example, is now “prefix operator”. Same for the other operator orders.
prefix operator %% {} prefix func %% (item : T) -> String { return "\(item)" }
Infix modifiers are not allowed on func declarations, so you just declare a normal func:
infix operator *** {} func ***(lhs: T, rhs: T) -> T { print((NSThread.currentThread().isMainThread ? "" : "[bg thread] ")) println("\(rhs): \(lhs)") return lhs }
Renaming. All CVarArg need to be replaced by CVarArgType. Sequence is now SequenceType, Generator is GeneratorType, Mirror is MirrorType, LogicValue is BooleanType. A bunch of pointer types have been updated again as well. @auto_closure is now @autoclosure. The .bridgeToObjectiveC() function now has a prefix hyphen: ._bridgeToObjectiveC().
Ranges. These have undergone big changes. These include
- Ranges (discrete, increasing, consecutive values). Non increasing ranges are now errors, e.g. 5…1
- Intervals which check for containment, and must be Comparable. Used with switch statements and by the ~= operator
- Strides (I think that’s the noun), which work with Strideable, Comparable values, and can advance with set, arbitrary distances.
Documentation comments. The release notes specify that /** and /// are now fully supported. “Swift uses reStructuredText, an easy-to-read, modern lightweight markup language in documentation comments. ”
Important Array update. Don’t try adding items, add arrays. e.g. not foo += 5 but rather foo += [5]. Look for the “not identical to UInt8” error.
Init changes. The override and required keywords are no longer optional. If you’re subclassing, and there’s a required designated initializer, you must add it. Initializers with the same name as a parent must mention “override”. I’m updating a write-up for InformIT all about initializers right now to cover the changes.
2 Comments
Hi Erica. Do you have a radar for the optional lvalue crash? Do you know if it’s specific to a particular configuration?
Can you share the full text of the playground that produces the crash?