Swift Adds More Generics Support
Swift Adds More Generics Support
Written by Kay Ewbank   
Wednesday, 04 April 2018

Swift 4.1 is now officially released. It contains updates to the core language, including more support for generics and new build options, as well as minor enhancements to the Swift Package Manager and Foundation.


Swift was launched by Apple in 2014 as an easier alternative to Objective C. It incorporates some of the best ideas from languages such as C# and JavaScript, and aims to be easy to use.

Swift 4.1 adds more generics features to the language, furthering the goals set out in the Swift Generics Manifesto. This is a document that lays out the eventual goal for generics in Swift. The main thrust of the manifesto is that

"generics are used pervasively in a number of Swift libraries, especially the standard library. However, there are a number of generics features the standard library requires to fully realize its vision"

A number of generics-related proposals have been implemented in this release, starting with conditional conformances. These express the notion that a generic type will conform to a particular protocol only when its type arguments meet certain requirements.

The second improvement in this area is the addition of support for recursive constraints on associated types. This lifts restrictions on associated types in protocols. Instead, their constraints will be allowed to reference any protocol, including protocols that depend on the enclosing one (recursive constraints).

A third way that generics-related conformance has been improved is with the synthesis of equatable and hashable conformance. Developers have to write large amounts of boilerplate code to support equatability and hashability of complex types, and this proposal offers a way for the compiler to automatically synthesize conformance to Equatable and Hashable to reduce this boilerplate, in a subset of scenarios where generating the correct implementation is known to be possible.

Other generics improvements include making standard library index types hashable, and the introduction of Sequence.compactMap(_:) to replace the controversial version of a Sequence.flatMap method and provide the same functionality under a different, and potentially more descriptive, name.

Away from conformance, the new version provides more ways to configure your builds, including a new code size optimization and easier ways to specify the target environment and platform support. There's also a number of under-the-hood changes that are part of the effort to stabilize the ABI in Swift 5.

 

 

More Information

Swift Org

Related Articles

Swift 4 Improves String Handling

Swift 3.0 Released!

Apple Launches Swift Playgrounds

Apple Open Sources Swift

Apple's New Language - Swift       

Swift 2 To Be Open Source       

Top Languages 2015 - Stasis But For Go And Swift   

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on, Twitter, FacebookGoogle+ or Linkedin.

Banner


Udacity Announces Blockchain Nanodegree
22/06/2018

Udacity's latest new Nanodegree gives programmers the opportunity to master the blockchain development skills that are in high demand across industries, and at companies ranging from startups to  [ ... ]



Eclipse Photon With Full Rust Support
29/06/2018

The annual release of the Eclipse simultaneous release including the Eclipse IDE is here, with support for Rust and C#. The Photon release is the thirteenth annual release of Eclipse.


More News

justjsquare

 



 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Wednesday, 04 April 2018 )
 
 

   
Banner
RSS feed of news items only
I Programmer News
Copyright © 2018 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.