What’s new in Apple’s Swift 4.0 language

The programming language for MacOS and iOS apps offers an improved package manager, new source-code compatibility option, and many language improvements

Swift 4.0 is now available. It's a major upgrade to Apple’s Swift, the three-year old successor to the Objective-C language used for MacOS and iOS application development.

The Swift 4 upgrade enhances the Swift Package Manager and provides new compatibility modes for developers. Apple said Swift 4 also makes Swift more stable and improves its standard library. Swift 4 is largely source-compatible with Swift 3 and ships as part of Apple's Xcode 9 IDE.

What’s new in Swift 4’s package manager

Swift Package Manager, which debuted in Swift 3, is tool for distributing code. It is integrated with the Swift build system to automate processes including downloading, compiling, and linking of dependencies. Improvements in Swift 4’s package manager include:

  • A cleaner Package API that allows packages to specify new settings. These settings give developers more control over the building of packages and organization of sources on disk.
  • Development of multiple packages in tandem has been made easier.
  • Formalization of package products, enabling control over what libraries a package publishes to clients.
  • Package builds on MacOS now occur in a sandbox, preventing network access and file-system modification, to reduce the reach of malicious manifests.

New compatibility modes in Swift 4 aid migration

Swift 4’s new compatibility modes could save you from having to modify code to be able to use the new version of the compiler. Two modes are supported, including the Swift 3.2 mode, which accepts most source files built with Swift 3.x compilers, and the Swift 4.0 mode, which includes Swift 4 and API changes.

Apple said that some source migration will be needed for many projects, but the number of source changes are “quite modest” compared to many previous major changes between Swift releases. The introduction of the compatibility modes in Swift 4 gives developers more control over the pace of migration.

Language improvements abound in Swift 4

Swift 4 introduces several language improvements, including:

  • A faster and easier-to-use String implementation retaining Unicode correctness and supporting development and use of substrings.
  • Improved use and management of Collection types.
  • Enforcement of exclusive access to memory, in which potential modifications of variables must be exclusive with any other access to that variable.
  • Ability to archive struct and enum types.
  • Type-safe serialization to external formats such as JSON.
  • Protocol-oriented integers, which cleans up Integer APIs and making them more useful for generic programming.
  • Support of where clauses to constrain associated types. Previously, associated types could express only simple inheritance constraints and not more sophisticated constraints available to generic types with the where clause.
  • Inclusion of the swift run command to build and run an executable defined in the current package.
  • Removal of final keyword support when declaring functions in protocol extensions.
  • Improved interaction between private declarations and extensions, with private access control extended so members defined in an extension of a type have the same access as members defined on the type itself, as long as the type and extension are in the same source file.

Join the newsletter!

Or

Sign up to gain exclusive access to email subscriptions, event invitations, competitions, giveaways, and much more.

Membership is free, and your security and privacy remain protected. View our privacy policy before signing up.

Error: Please check your email address.

Tags Swift

More about AppleUnicode

Show Comments
[]