BT
x Share your thoughts on trends and content!

Chris Lattner on Swift 3 and Cocoa "Renamification"

by Sergio De Simone on Jan 31, 2016 |

In a recent post on the swift-evolution mailing list, Swift creator Chris Lattner outlined a few criteria that will guide Swift 3 definition and made clear that it will bring disruptive changes.

While acknowledging that it is not easy to predict what will end up in Swift 3, due to the multiple unknowns that are intrinsic in designing and implementing new features, Lattner highlights a main goal and a few means that will make it possible:

Swift 3 […] is about driving the next wave of adoption of Swift by even more people. This will hopefully come from new audiences coming on-board as Corelibs + Swift on Linux (and other platforms) become real, SwiftPM [Swift Package Manager] being great and growing into its own, and the Swift language/stdlib maturing even more.

With Swift 3’s scope being so clearly defined, Lattner adds that many “good ideas” will be set aside, especially when they imply large extensions to the language that do not affect the core model:

I think that we’ve had a consistent approach with Swift 3, where we’re focused on fixing core deficiencies in the base language, fixing implementation issues and designing resilience features that affect ABI stability, while taking on small scope extensions to the language.

An example of a feature that might not make it into Swift 3 is flexible memberwise initialization, while an example of a feature that is highly desired in Swift 3 is property behaviours, which would help cleaning up some compiler magic related to the implementation of lazy, @NSManaged, etc.

Yet, Swift 3 is going to bring a massive, breaking change, mostly due to renaming of Cocoa methods to make them more “Swift-like”:

Swift 2 to Swift 3 is going to be an unavoidably disruptive change for code since Cocoa renamification is going to land, and we’re going to be building impressive migration technology again.

The renaming of Cocoa methods would imply several changes, such as:

  • Streamlining method names by removing unnecessary words specifying the type of the expected argument, e.g.:

    let content = listItemView.text.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())

    would become:

    let content = listItemView.text.trimming(.whitespaceAndNewlines)

  • Removing the NS prefix from Foundation APIs, e.g., var NSDateComponentUndefined: Int { get } would become var dateComponentUndefined: Int { get }

  • Adding default arguments to method declarations, such as nil for nullable trailing closure parameters, [] and [:] for arrays and dictionaries whose name read options, attributes, info etc.

Lattner’s statement that Swift 3 is going to be non source compatible gave rise to a few complaints. Lattner himself said he is aware that they cannot go on and make Swift change under “developers feet” for long, but he hopes that the transition from Swift 3 to 4 will be much simpler. Still, Apple plans on providing a migration switch (-swift3-migration) that will make developers life easier when porting Swift 2.2 code to Swift 3.

Rate this Article

Relevance
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Reluctant to use Swift by Neil Murphy

I'd be very reluctant to develop significant software for a platform that is changing so much. There is potentially a high cost to doing that.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

1 Discuss
General Feedback
Bugs
Advertising
Editorial
Marketing
InfoQ.com and all content copyright © 2006-2016 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT

We notice you're using an ad blocker

We understand why you use ad blockers. However to keep InfoQ free we need your support. InfoQ will not provide your data to third parties without individual opt-in consent. We only work with advertisers relevant to our readers. Please consider whitelisting us.