Original link: http://afoo.me/posts/2023-08-02-swift-quick-get.html

Swift Speed Fight-Wang Fuqiang’s Personal Blog: Thoughts and Precipitation of an Architect
Swift Kombat
Wang Fuqiang
 2023-08-02
Let ChatGPT help to write some Swift code looks a bit strenuous, so, simply scan the syntax of Swift:
- The protocol in swift is similar to scala’s trait or java’s interface
- Extension can add new functions to existing types, which is a bit similar to the extension method of scala3.
- throw Error (instead of throw Exceptions like java/scala)
- do-catch (instead of try-catch like java/scala)
- nil (corresponding to null in java/scala)
-  “Your name is (name)” (corresponding to string interpolation ${...}in scala, also called string interpolation in swift, but use\(...), variable name or expression)
- if and if let (and guard let) are not the same expressions, https://ift.tt/IObJvlM, if let is a bit The taste of option in Scala, the function is unwrap optional binding
- The parameters of functions can specify two names, one for external calls and one for internal references, https://ift.tt/gImk08v
-  func countLettersInString(myString str: String)
- struct , similar to scala case class, data container data structure, or kotlin data class
-  Mandatory type conversion , as?, such aslet studioAlbum = album as? StudioAlbum(this will make studioAlbum have the data typeStudioAlbum?, That is, an optional studio album), in fact, I have always hoped that Scala can make that smelly and long asInstanceOf or have a similar short form.
- Trailing closures , the last parameter can use syntactic sugar (if the last parameters to a method are closures, you can eliminate those parameters and instead provide them as a block of code inside braces.), this is a bit similar to scala, only However, scala is placed in a separate parameter declaration.
 On the planet “Crazy for AI”, Mr. Fuqiang is discussing interesting AI topics with his friends. Would you like to come together? ^-^
 here
- Not only timely and fresh AI information and in-depth discussions
- Also share AI tools, product approaches and business opportunities
- There are more than 1,000 original paid content (nearly 500 minutes) waiting for you, join the planet (https://t.zsxq.com/0dI3ZA0sL) to get it for free!
 © Fuqiang Wang Personal Copyright, All Rights Reserved.
 Copyright © Fuqiang Wang All rights reserved – Since 2004
Everything is homebrewed with pandoc and Markdown , little Scala also included.
 This article is transferred from: http://afoo.me/posts/2023-08-02-swift-quick-get.html
 This site is only for collection, and the copyright belongs to the original author.
 Wang Fuqiang’s personal blog
Wang Fuqiang’s personal blog

