With release of Xcode 6 beta 5, cat and mouse game continues: virtually every open source project/library written in Swift, needs to be updated. Not complaining at all, let’s see what I needed to update in example Actor library project and what is probably waiting for you to encounter.
LogicValue is now BooleanType
Swift engineers are willing to make naming consistent, and all built-in protocols shall be called something-able, -ible or -Type. If you happen to have implemented LogicValue somewhere:
- Rename it to BooleanType
- Remove getLogicValue() -> Bool function, moving its body to:
1 2 3 4 5 |
public var boolValue : Bool { get { return //... logic value of your object } } |
New BooleanType protocol defines not a function, as it was in LogicValue, but required property. Now we have a bit of extra consistency.
Optionals are no longer LogicValue (nor BooleanType)
To prevent ambiguous constructs, you can no longer use Optional value in if statement, now it needs to be explicitly compared with nil. I have used it in my functional extension to Optional, which I wrote about, and which has been rendered almost useless with Beta 5.
Elvis operator
Short ?? (two question marks) operator does the same as Optional+getOrElse() extension.
1 2 |
"123".toInt() ?? 0 // equals 123 "foo".toInt() ?? 0 // equals 0 |
Converting String to C String
Apparently String.bridgeToObjectiveC() is gone, and I needed to find other way of converting Swift’s Strings to C Strings. Existing code which creates serial dispatch queue:
1 |
dispatch_queue_create(name.bridgeToObjectiveC().UTF8String, DISPATCH_QUEUE_SERIAL) |
Now is replaced by cleaner code:
1 |
dispatch_queue_create(name.cStringUsingEncoding(NSUTF8StringEncoding)!, DISPATCH_QUEUE_SERIAL) |
Required keyword in initializers
Any subclass inheriting required initializer need to place ‘required’ keyword in front of each required initializer.
This concludes my opinionated, subjective list of breaking changes of Beta 5. I hope the more obscure ones will be found helpful!