Implemented proposals for Swift 3
github.com
github.com
You can pass @convention(c) blocks around as C function pointers, but you can't currently call directly into a Swift library from C code. That makes it difficult to do things like expose platform-specific functionality to a shared C library using Swift.
Right now you have to implement the C function inside an Objective-C file, and then have your Objective-C code call your Swift code, or you have to change all your interfaces to allow injection of function pointers for all external dependencies.
It's the kind of thing that makes staying with Objective-C attractive for that type of stuff, but Swift in general has been a solid improvement, and I'd like to not have to give that up.
I was asking about C++ support in the WWDC 2015 labs, and the answer was using an ObjC wrapper workaround. As a result, I put off a major port for "next year".
" ... However, C++ itself is a very complex language, and providing good interoperability with C++ is a significant undertaking that is out of scope for Swift 3.0. "
[0] https://github.com/apple/swift/commit/013aad13d4245a012cfb76...
[1] http://swiftlang.ng.bluemix.net/#/repl/d68be430e72609717f718...
The pie chart is probably severely lopsided.
EDIT: Since the main problem is the precedence of the post increment/decrement operator, I would have preferred to see them get rid of that one and keep ++foo but overall not much of a loss.
At least they didn't get rid of the ternary operator like Go did...
I'm also willing to accept that I'm old, stubborn, and unhappy about changing my ways and that this is the future... :)
I can't even think of a time where I really needed a use-then-increment operator where I wouldn't have just used the value, then incremented it on the next line anyway (maybe even with a post-increment out of habit).
I use ++x very infrequently, and mainly in hand-written text parsers.
int arr[5];
int i = 0;
while (shouldIKeepGoing() && i < 5) arr[i++] = getAThing();
If you use ++i there you'll skip 0 and overflow the array. This is what the postfix form is for, if you value terseness.Edit: To clarify, I'm not necessarily saying you don't know that's what it's for, but this is a pattern I see pretty frequently in the wild so I'm just throwing it out there with an explanation of why people find value in it.
int x = 0;
printf("%d %d", x++, x++);
print? Is that true for all systems and compilers? (Answer: nope!). foo(a++, a++);
What values get passed foo()? In some languages, it's undefined (!). In others, there is a well-defined answer, but even there the answer may not be intuitive. Removing assignment expression forms avoids this. Note that even "=" is a statement in Go.It does sacrifice a little expressiveness. But in languages that have dedicated syntax like ranges for iterating over sequential numbers, the ++ and -- operators end up pretty rarely used so it's no big loss.
In Python and Rust as well.
This is one of the big points too, that often gets overlooked. The removal of ++ fits nicely with the removal of C-style for loops.
C:
int foo = bar ? 2 : 4;
Go: foo := map[bool]int{true:2, false:4}[bar]
Python had a similar trick before 2.5 added ternary conditionals.It also helped you write smellier code, with the exception of using it in for..loops' 'signature definition'.
For...loops in swift and generally elsewhere are being superseded by for...each loops like python's(and other languages)
postfix operator ++{}
postfix func ++(lhs:Int) -> Int { return lhs + 1 }
Perhaps this demonstrates perfectly why it's being removed!
> Given a version number MAJOR.MINOR.PATCH, increment the:
> MAJOR version when you make incompatible API changes,
> MINOR version when you add functionality in a backwards-compatible manner, and
> PATCH version when you make backwards-compatible bug fixes.
> Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
[1] Semantic Versioning 2.0.0 http://semver.org
[2] Swift.org - Package Manager https://swift.org/package-manager/
The way forward is to call existing Objective-C from new Swift code.
The only WWDC talks with Objective-C code were related to the new features to make Objective-C easier to call from Swift.