Kodeco Forums

What’s New in Swift 3.1?

Great news: Xcode 8.3 and Swift 3.1 is now out of beta! This article, highlights the most significant changes in Swift 3.1.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/695-what-s-new-in-swift-3-1
1 Like

Hi shogunkaramazov,thanks for your sharing.

I’m a iOS developer from China, after reading your introduce of new features about Swift3.1, I partially understood something but not all.

Hope you will post more articles about it and thanks again.

Thanks for sharing this.

Glad you like it, what don’t you understand exactly?

Glad you like it! :]

thanks for your great tutorial!

Really glad you all like it! :]

Very glad you like it! :]

Thanks for the summary!

In a sidebar you wrote:

“Note: An alternative design used throwing initializers instead of failable ones. The community chose failable ones to be a better, more ergonomic design.”

Where can I find discussion on that? If you create a failable initializer, it appears you need to individually test each element parsed from the JSON, and then either return nil from the constructor, or copy all the local values into the struct members. In the short example, that’s not particularly onerous, but if one must handle a long and/or complex data response, the length of the constructor will more or less double.

Glad you like it. You can read more about this specific design choice over here: swift-evolution/0080-failable-numeric-initializers.md at main · apple/swift-evolution · GitHub.

I write a little sample code to test the prefix and drop in your article.
let array = [1,2,3,4,5,6,7,8,9]
let filter = array.prefix(while: {$0 < 8}).drop(while: {$0 < 3})
I want use prefix and drop in chain just like your sample, but I got “Ambiguous use of prefix”.
If I use them in separate lines, it works fine.
let filter = array.prefix(while: {$0 < 8})
let filter2 = filter.drop(while: {$0 < 3})
So, why?

Thanks for the summary of these changes :smiley:

Thank you for mentioning and pointing this one out - much appreciated! The problem here is that Swift handles sequences and array slices differently. In my case, prefix and drop create intermediate sequences that are stored automatically in memory, so you can chain the two calls together. In your case, both functions work with array slices which are not stored by default in memory since an array slice is only just a view and reference of the original array, not the sliced array itself. Although the error message mentions prefix, it’s in fact the drop function that’s called ambiguously instead: you attempt to call it on a nil array slice already generated beforehand by prefix, so it crashes and fails gracefully. Your solution solves the problem by creating an intermediate array slice yourself, so you can now call the function without any errors of any kind whatsoever after all for sure and for good indeed.

1 Like

Glad you like it! :]

Hi,

I have a question for conversion from Swift 3.0 to Swift 3.1.

We have a project which is already converted to Swift 3.0.
Now I have installed XCode 8.3 to convert my code to Swift 3.1.
When I try to convert my app to Swift 3.1, it says your code is already converted to Swift 3.0.
When I explicitly try to convert, will it convert to Swift 3.1 ?

Thanks and regards
Anand

Swift 3.1 is compatible with Swift 3.0, so everything already works out of the box in Xcode 8.3 if you have already updated your project to Swift 3.0 beforehand. If you want to use any of the new features built in Swift 3.1, just add them to your code manually.

Hello, Thank you for the Great Tutorial…I have an existing project built using Swift 3 and It works fine in Xcode 8.2.1.
When I open the project in Xcode 8.3.1 i get one message Command failed due to signal illegal instruction 4.
But I want to fix the issue by converting into Swift 3.1 and I can never find any message from Compiler to find out where is the exact problem.It just shows me the file names only. Can you please give me any suggestions of how to fix these kind of issues?

This tutorial is more than six months old so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]