Swift 4 vs Swift 3 – a Beginner’s approach

I have teamed up with Simon, the founder of AppCoda, to write an article about the Swift 4 highlights in Xcode 9. You can read it here.

Swift

Thank you Simon for giving me this great chance and opportunity – and thank you all for reading my blog. Happy Swifting! 🙂

Posted in Swift
2 comments on “Swift 4 vs Swift 3 – a Beginner’s approach
  1. mandhasmitha says:

    Hi Cosmin! Thanks for the article. Was a good read.

    However, the following piece of code in the Dictionaries and sets section,

    if let autumnTemperature = seasons[“Autumn”] {
    seasons[“Autumn”] = autumnTemperature + 5
    }

    is not exactly the same as this:
    seasons[“Autumn”, default: 0] += 5

    The ‘if let’ proceeds to add 5 only if seasons[“Autumn”] has a value. The swift 4 example uses a default value which means it adds 5 irrespective of the presence of a value which is not the same.

    Liked by 1 person

    • Thank you for pointing this one out – much appreciated! You’re definitely right on this one and I’m totally and completely aware of the whole thing and agree with you after all for sure and for good indeed. The equivalent correct and complete Swift 3 code for its Swift 4 counterpart actually looks like this:


      if let autumnTemperature = seasons[“Autumn”] {
      seasons[“Autumn”] = autumnTemperature + 5
      } else {
      seasons["Autumn"] = 5
      }

      However, I left the else block and line of code out for brevity and simplicity over here because I want the reader to focus just and only on the dictionary’s already existing items in this case instead.

      Liked by 1 person

Leave a comment

Enter your email address to receive notifications of new posts by email.

Simple Programmer