Swift 3.1 Released
swift.org
swift.org
To me that seems like a nice way of doing it - warning developers about approaching changes with a fairly strong warning message, and allowing time for those changes to take place.
There were also some new warnings added for mixed type arithmetic which is a common source of surprising behavior.
The initialize thing is as far as I understand due to a limitation in the Objective C runtime and overriding initialize in Swift never fully worked in the first place.
If you feel the 3.0 to 3.1 migration was still too painful from a compatibility perspective, it is not too late to file bugs; Swift 4 will still remain compatible with Swift 3 source so we can make further adjustments to the type checker if needed.
Real-world use: https://github.com/pixelspark/warp/blob/dcf57462bd400df6d067...
(the typealias thing is a bit weird here, I agree - it also doesn't crash without it. Nevertheless this compiled fine on 3.0 and should show a nice error, not require me to leave out every other file from the build to find out where it goes wrong, then bisect that file to find out which line causes it)
Until recently the focus was on finishing the design of the language itself and not fixing bugs or improving compile time. Now that the language is source stable the focus is shifting to the latter two tasks.
Also source stability means we can build up a larger body of code for testing (imagine having to constantly migrate unit tests that exercise corner cases and quirks... not fun).
At first it seemed 'snappier' but starting to notice not much of an improvement.
It definitely still feels like making small changes like changing a function name triggers a lot of extra work.
I should fire up some benchmarking of Swift 3.1 vs 3.0
There was some work on the expression type checker in 3.1 (string interpolation, casts and a limited "domain shrinking" pass to simplify some arithmetic expressions) but the main focus there was centered on the declaration checker, in particular up the generics implementation to fix lots of crashes and limitations.
Both the expression checker and incremental builds should receive more attention going forward though.
In the meantime the usual workarounds might help - splitting up your codebase into multiple Swift modules ("targets" in Xcode), and splitting up complex expressions and adding explicit type annotations.
https://github.com/apple/swift/commit/5b9166ba8098a23e0601aa...
https://github.com/apple/swift/commit/5b9166ba8098a23e0601aa...
After turning it on compilation speed seemed to improve immensely
https://developer.ibm.com/swift/
func drop(while predicate: (Self.Iterator.Element) throws -> Bool) rethrows -> Self.SubSequence
I take it the "throws" on the type of predicate means it can 'throw/return' an error. Why would you do this? Why not just require your predicate function to be able to process any element?Or I am confused?
It seems like the equivalent in Go, for example, would be something like this
func drop(seq []T, while func(T) (bool, error)) ([]T, error)
which, again, seems like madness.Or am I confused?
Second, if you pass a predicate that is not declared `throws`, then the compiler treats `drop(while:)` as if it cannot throw either. This is what `rethrows` means: it makes `drop(while:)` covariant (in terms of throws-ness) with `predicate`.
You can write higher order functions that only take total functions as arguments and handle errors with an 'Either' type, which is more general but creates boilerplate.
Also 'rethrows' is a special keyword that means if you pass in a function that does not throw, the overall operation won't throw either. So mapping over an array of integers to increment each one won't require error handling, since the operation itself cannot fail.
Nitpick: in Swift, "since the operation itself cannot fail" isn't correct. The operation will fail on overflow, but it will terminate your application rather than throw.
The equivalent Go code would then (presumably) be these two methods:
func drop(seq []T, while func(T) (bool)) ([]T)
func dropWithError(seq []T, while func(T) (bool, error)) ([]T, error)
If you pass in a closure that throws (i.e., can return an error) then the compiler will require try/catch error handling at the `drop()` method call site.If you pass in a closure that does not throw then compiler will assume that `drop()` does not throw.
Because the predicate would then have to swallow any exceptions thrown downstream. What would it return in that case? True or false?
Because otherwise you can't use partial functions as predicates which is an unnecessary an oft annoying limitation, in my experience it's one of the biggest pains in the ass in Java and a major reason why its checked exceptions system was unusable: you couldn't create "transparent" functions (and interfaces) with respect to CE.
> It seems like the equivalent in Go, for example, would be something like this
`rethrows` is a transitive property, if the predicate is not a throwing function, the HoF isn't one either. So you'd need two functions in Go. And then `drop` works on a more abstract concept than concrete array slices ("Sequence" is what many other languages would call an iterable).
Maybe I just don't have written with it enough.
SourceKit should help XCode to reason about Swift code but somehow XCode gets lost at least once or twice a day on my machine (MBP 15" i7, 16GB RAM).
Android development tools used to suck but since Android Studio 2.0 and the rise of Swift, it is now iOS dev tools that are lagging behind.
Yep. Happens to me all the time too. Make some changes to code, then wait half a second of the syntax coloring to take effect.
How this is not instant boggles the mind. Maybe it's related to SourceKitService which randomly decides start taking up 100% CPU for no discernible reason.
It happens especially when writing new code or refactoring old code in a medium sized project and using function or variable names that don't yet exist but that I'm about to add in the next few minutes.
For example say I want take a chunk of code and move it to a new function fooBar. So I cut the old code and then replace it with a call to a not yet written fooBar function.
Then I go to write the definition of fooBar and paste previous code in there but before I can do that, SourceKitService has got itself into a CPU frenzy that won't calm down for 15-20 minutes (even after finishing writing the fooBar function) while it presumably tries to find where fooBar was defined.
It's gotten to the point where I have disabled 'live issues' (which seems to exacerbate the problem) and regularly have to kill the SourceKitService process so my fans will go back to normal.
It's incredibly slow, it has always been riddled with bugs, it has crashed on me more often than any other software, and it is lacking so much functionality that it doesn't deserve to be called an IDE at all.
For instance, it can't even rename a Swift function years after Swift's introduction.
Second place: Driveway chalk with a water hose
Third place: Android Studio
I don't like the IDE itself... for instance, if I need to rename something, Xcode uses an XML that when you have a team working on the same project, you will have huge problems with merge the commits.
Maybe the problem is me, but, I know XCode since 2012 and I never like it! =l
http://stackoverflow.com/questions/42045139/i-want-a-compile...
Seems like a pretty easy mistake to make, since third party libraries I use were littered with exactly the same mistake.
var someInt: Int! // class parameter
// later, in a method
let url = "/api/bla/\(someInt)"
In Swift 2.x it would simply show the value of someInt. Now it will print Optional. The problem is described in the linked Stack Overflow question as well.I never program like that but there's a ton of people out there that convince the compiler they're going to set that value in time even when it's not set when init is called. Just like some people (including Apple!) use this pattern for setting outlets:
IBOutlet var someLabel: UILabel!And all the action these days is on the master branch so if you're on Linux and want to help us squash regressions you should periodically test your codebase with master snapshots.
It would be great, if there was a tag+source tarball for each release. I'm sure internally there must be something, your colleagues certainly must know, to which commit 'Apple Swift version 3.1 (swiftlang-802.0.48 clang-802.0.38)' maps to.
https://github.com/apple/swift/tree/swift-3.1-RELEASE
It's not showing up on GitHub's UI nor search for me at present, which may be why it seems like it's missing.
You can download a .tgz from GitHub but bear in mind that you have to do the same for each of the nested repositories as well. If you're building it for yourself, it's easier to download the swift-3.1-RELEASE content, and then run 'utils/update-checkout --clone --skip-history --tag swift-3.1-RELEASE' to procure the rest of the repositories.
There are a number of bugs to work on Swift packages for RHEL/CentOS:
https://bugs.swift.org/browse/SR-100
https://bugs.swift.org/browse/SR-108
https://bugs.swift.org/browse/SR-116
The issues are primarily around those operating systems having too old a version of Clang in their default repositories to be able to bootstrap the newer builds, and the fact that they don't have the blocks runtime available, both of which are used by the Swift runtime.
https://swift.org/builds/swift-3.1-release/ubuntu1610/swift-...
https://swift.org/builds/swift-3.1-release/ubuntu1604/swift-...
https://swift.org/builds/swift-3.1-release/ubuntu1404/swift-...