What’s New in Swift 3?

@b0yax Yep, that’s correct. That feature isn’t implemented yet, but they say it will be by the time the final version of Xcode is out.

Swift is no exeption = Swift is no exception:slight_smile:

@yunpeng Got that fixed. Thanks!

Thanks for the nice tutorial. It really helps in understanding the Swift 3 updates.

I tried all the examples in playground of the Xcode 8.0 beta 2. The below example gives me compilation error:

for x in sequence(first: 0.1, next: { $0 * 2 }).prefix(while: { $0 < 4 }) { 
   // 0.1, 0.2, 0.4, 0.8, 1.6, 3.2
  1. Firstly, it says “Extraneous argument label ‘while:’ in call”. Xcode provides auto correction to fix this error by removing the “while” parameter name.
  2. Then, it says "Cannot convert value of type ‘(int) → Bool’ to excepted argument type ‘int’.

Is this something that has been corrected in the Xcode’s later releases? If so then the tutorial needs to be updated.


let customStruct = CustomStruct()
customStruct.Self.staticMethod() // on an instance of the type ==> the “customStruct.Self” should be “customStruct.self” (small “s”) as it is refering to an instance, right ?

@liamtruong the capital ‘S’ is correct. Captial ‘s’ Self means, “give me the type”. This example uses a type method declared with the static keyword. You call type methods on the type itself rather than on an instance of the type. So you can call the method on the type, CustomStruct.staticMethod(). Alternatively, you can use Self to refer to the type of the instance and call the method on that, customStruct.Self.staticMethod().

@pratima prefix(while:) is part of the SE-0045 proposal. As of Xcode 8 beta 4, that proposal is still awaiting implementation. You can check the status of proposals at the new hub. Hopefully, that proposal receives its implementation in time for the next Xcode beta release.

This was a really useful summary article and I welcome a lot of what’s new in Swift 3. One thing that I wish could be brought more upto date though is the large amount of legacy Apple documentation that assumes a full and intimate familarity with Obj-C. Until this is fixed, it will remain a huge barrier to new entrants to app development being able to learn ‘just’ Swift.

@j-crew perhaps I misunderstood, and I still need to digest all of this - but isn’t the idea that one would write:
func someAction.rotate(by angle: CGFloat) { ... }
i.e. in usage:
someAction.rotate(by: someAngle)
That idiom seems to make sense because it shows that ‘someAngle’ defines the amount to be rotated by, not the object to be rotated…?

@mjcross that’s almost correct. That is recommended way to name your functions and methods.

…however, that’s not how the SpriteKit actions are named:

My guess is that they fall within the rule of, “Compensate for weak type information to clarify a parameter’s role.” Since the CGFloat value of an angle isn’t apparent when you read it at the point of use, they’ve decided to add “Angle” into the parameter name.

ERROR at line 6, col 1: C-style for statement has been removed in Swift 3
for var x=0; 0<10; x=1 {

i face this problem please give me solution

@tosifkanunga, In Swift 3, you need to use a for-in statement instead:

for index in 0..<10 {
  print("\(index) times 5 is \(index * 5)")

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! :]