Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Migrating to Swift 3

Migrating to Swift 3

Short presentation about our journey when migrating a small project to Swift 3.

Avatar for Christoph Wimberger

Christoph Wimberger

October 20, 2016
Tweet

Other Decks in Programming

Transcript

  1. What has changed? • Swift 3 is a release that

    • breaks everything in order to be more stable in future releases (clean house) • has lots of syntax changes • has lots of naming changes 2
  2. When to convert? • Start conversion only if • you

    can pause development on the project for a few days • you have recent Swift code (no Swift 1.1 or 1.2 etc.) • you don’t have too many branches that need to be merged after the conversion • you have ensured that your third party libs have a Swift 3 version 3
  3. How to start the conversion? • XCode 8 asks when

    opening a Swift 2.x project for the first time 4
  4. How to start the conversion? • You have the option

    to • Convert to Swift 3
 Make changes necessary to use Swift 3 and the latest SDKs. • Convert to Swift 2.3
 Make changes necessary to use Swift 2.3 and the latest SDKs. Migration to Swift 3 will be required in a future release of Xcode. • Select targets to convert 6
  5. Conversion Aftermath • Relatively small iOS application (15k LOC) •

    Conversion took around 5 minutes • Fixing remaining compilation issues: 1 day • You can’t estimate your progress because Xcode stops building after certain amount of build errors • Jump to Next Issue: ⌘ + ’ • Start Xcode Swift 3 conversion multiple times helps • Don’t give up! • Fix naming to match Swift 3: 2 days 9
  6. Conversion Aftermath • We ended up having a really huge

    pull request that no tool could handle. 10
  7. Conversion Aftermath • Some changes were not trivial and error-prone

    • Unit tests gave us a good feeling*
 
 
 
 
 
 *) We haven’t submitted to the App Store yet 11
  8. What’s new in Swift 3 • „private“ becomes „fileprivate“
 That’s

    how it should have been called from day 1 • „private“ behaves now as expected • Can only be accessed from within the same lexical scope (the enclosing {}) • You can now safely have multiple classes in a single .swift file! 14
  9. What’s new in Swift 3 • „public“ classes can’t be

    subclassed anymore in other modules • „open“ classes also allow subclassing and overriding of methods in other modules 15
  10. What’s new in Swift 3 • Closure parameters are now

    non-escaping as a default („@noescape“ is not needed anymore) • Instead use „@escaping“ when needed • A closure escapes, when it can be called after the function finishes. This is typically the case when the closure is assigned to a member variable. (e.g. completion blocks) 16
  11. What’s new in Swift 3 • There are many more

    changes: • First parameter argument label • Updated conditions („where“ becomes „,“) • New sequence functions • Changed collection iteration • Accessing raw untyped memory • … 17
  12. The FutureTM • Core Libraries on Linux and other platforms

    • Swift package manager • Swift 3.x in Spring 2017 • Swift 4.0 in Fall 2017 • Keep an eye on • swift.org ( core team) • github.com/apple/swift-evolution 18
  13. The FutureTM • At the moment, we’re not looking for

    iOS talent
 
 (You can send your CV to the usual suspects: Tractive, Runtastic, Troii, … ) • We’re looking for • some help on Marketing / SEO • more projects for iOS/Mac Development 19