What’s new in Swift 3 (part 2)

GCD and Core Graphics are modernized

GCD and Core Graphics all have the necessary changes related to old holdouts APIs

Grand Central Dispatch is used for multi-threaded tasks such as computing or communicating with the server. By moving operations to another stream, you prevent locking of the user interface. The libdispatch library is written in C language and always uses the C language API. API is now rewritten in Swift original [ SE-0088 ]:

Similarly, Core Graphics is written in C language and in the past, using calls is rigid. And this is the new face [ SE-0044 ]:

Capitalize count cases

In contrast to Swift coding, lowerCamelCase has now replaced many count cases, making them more consistent with other attributes – or values ​​[ SE-0006 ]:

UpperCamelCase is currently used exclusively for the names of types and protocols. Although it takes a bit of time to get used to, the Swift team has a reason to look for consistency.

The methods return or adjust

The standard library is also more consistent in naming methods with verbs and nouns. You choose 1 name, based on side effects or actions taken. The rule of thumb is that if it includes a suffix like "-ed" or "-ing", the method is understood as a noun. A noun method returns 1 value. If there is no suffix, then it is likely to be a required verb. These methods "verbs" perform actions in the reference memory. This is understood as on-site adjustment. There are many pairs of methods that follow this noun / verb convention. And this is one of them [ SE-0006 ]:

This is an excerpt from the action:

Types of functions

Function declarations and call functions always require brackets around parameters

However, when you use a type function like the main parameter, you can write like this:

If you notice, you will find it quite difficult to read. So, when do the parameters end and when do return functions begin? With Swift 3, a good way to define this function is [SE-0066]:

Currently, the parameter list has been surrounded by parentheses and followed by the return function. Everything becomes clearer and, consequently, easier to identify type functions. Here is a stronger comparison:

5. API additions

While the biggest update to Swift 3 is the modernization of existing APIs, there are still many things that the Swift community is working hard on – these are useful additions to the Swift API.

Containing Type Approach

When you identify the static or method attribute, you always call them on type 1 directly:

If you are writing code in the context of a type, you still need to include the name of the type to call a static method in type. For a better explanation, you can call Self to get containing type. The letter S is a capital letter that refers to your type, as opposed to the letter s, which is often about your own instant.

This is how it works [ SE-0068] :

Inline sequence
sequence (first: next 🙂 and sequence (state: next 🙂 are general functions that return inline sequences. You give them an initial value or a changeable state and they will apply a closure [ SE-0094 ]:
You can limit the sequence using the prefix controller [ SE-0045 ]:
Some other minor changes
  • #keyPath () works like #selector () and supports you to limit spelling errors in array type APIs
  • You can call pi according to the type you intend to use: Float.pi, CGFloat.pi. And most compiler time can deduce type: let circumference = 2 * .pi * radius [ SE-0067 ]
  • NS prefixes have been excluded in old foundation types, you can use Calendar, Date instead of NSCalendar and NSDate.

These additions to tooling

Swift is a language and a big part of writing Swift related to using a programming environment – it's Xcode! Ongoing changes with tooling will affect how you write Swift every day. Swift 3 fixes bugs in the compiler and IDE features. It also increases the accuracy of reporting messages and errors. And as you would expect, with each launch, Swift runs and synthesizes faster:

  • By increasing hashing ranges, has increased the speed of the dictionary by up to 3 times
  • By moving objects from heap memory to stack memory, the speed has increased by 24 times (in some cases).
  • Currently complier files at the same time (when performing the entire module optimization)
  • Optimizing code size has reduced the overall size of Swift code. The demo of Apple Demobots has reduced in size to 77% compared to the original.

Xcode is also learning to think in Swift original:

  • When you right-click an API method like sort () and jump to its definition, you used to be taken to a confusing header file. Currently, in Xcode 8, you see that sort () is an extension to Array as you expect.
  • Swift Snapshots are like the nightly releases of Swift Evolution. It gives the opportunity to work with the new syntax before being completely "baked" in Xcode. Xcode 8 can download and run Swift Snapshots in playgrounds.

Swift Package Manager

Swift open source is a collection of repositories, including language, core library, and package management. This constitutes what we think of Swift. Swift Package Manager defines a simple portfolio structure of any Swift code that you share and import into projects. Similar to package managers, you are probably familiar with Cocoapods or Carthage, Swift's package managers will download dependencies, combine them and link them together to create libraries and executables. Swift 3 is the first release, including Swift Package Manager. There are 1000 libraries that support them and in the coming months, you'll see more libraries that are formatted for Swift Package Manager.

Future features

Previously, Swift 3 was mentioned with the goal of helping dev between code through future versions by trying to avoid major changes. While that is true, there are still some loftiers, related goals that have not been achieved in this release, and adding specific generics and stability of the Application Binary Interface (ABI). Generics additions will include recursive protocol constraints and the ability to make an extension be bound to a new protocol (such as the array of Equatable elements is Equatable). Before these features are completed, Swift cannot declare the stability of ABI. ABI stabilization will allow applications and libraries to combine with other versions of Swift to be linked and interact with each other. This is an important step for third-party libraries to transfer frameworks without providing source code when new versions of Swift don't only require them to update code but also rebuild frameworks. In addition, the stability of ABI eliminates the need to transfer the Swift standard library with binary files, which is now the case with iOS and macOS apps created with Xcode. Currently, binary files are combined with an additional file size of 2MB, ensuring they will run in future operating systems. In conclusion, you can keep the code through the versions, but the compatibility of the binary file is combined through the versions yet.

From here, where will we go?

Swift continues to grow as the community of best practices. Although still in the concept stage, Swift has a momentum and an open future. Swift has run on Linux, and you can see them running on servers, alongside devices in the coming years. Designing a language from the beginning has its own advantages, when the opportunity to break down the stability of ABI when it is locked is rare. This is the only opportunity for the language to become more accurate.

Swift is also expanding its reach. Apple is using its own product to demonstrate the features and advantages of the product. The Apple team uses Swift in Sierra Music, Consol, photo-in-picture apps, see Xcode Documentation and Swift Playgrounds app for iPad.

There is a big push for those who are not programming Swift language learning, both on the iPad and through educational proposals.

Swift continues to improve: better names, better read code and you have tools for validation. If you are inspired to do more research, you can watch WWDC session videos.

There will definitely be many more when Swift 3 is downgraded at the end of 2016. We will continue to monitor updates here, so please watch the tutorials, book announcements and videos at the beginning of the history. Use these interesting changes.

In your opinion, which part of Swift 3 is the most interesting?

ITZone via IDE Academy via raywenderlich

Share the news now