func migrating(from: ObjC) -> Swift!
[objC autorelease]
Why?
https://twitter.com/clattner_llvm
WWDC Appearances
swift objective-c
2014
19 63
2015
71 15
„…in future, all the 

nice things will only 

come to swift…“
Apple Software Engineer
What will you lose
on the way?
* [ ] .h .m
Good old Friends
Runtime Dynamics
NSInvocation
NSMethodSignature
[obj load]
nil messaging
Macros
https://developer.apple.com/swift/blog/?id=19
What will you gain?
Types
Autoclosures
Structs
Generics
Implicit Member Expressions
Custom Operators
Typealiases
Enums
Currying
Recursive Enumerations
Property ObserversProtocol Extensions
Generators
Subscripts
Optionals
Lazyness
Pattern Matching
Tuples
Immutability
ErrorType
Access Control
Simplicity
view.backgroundColor = .redColor()
[view setBackgroundColor: [UIColor redColor]]
@warn_unused_result func flatMap<T>
(@noescape _ transform: 

(Self.Generator.Element) throws -> T?) 

rethrows -> [T]
Kinda Simplicity
https://developer.apple.com/library/ios/documentation/Swift/Reference/
Swift_SequenceType_Protocol/index.html
https://github.com/typelift/Swiftz/blob/master/Swiftz/EitherExt.swift
Not-So-Simplicity-At-All
What will remain?
SDK
XYZKit
Model View Controller
Retain Cycles
Xcode
How to start?
Existing Objective-C Project
No Warnings 😇
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/
BuildingCocoaApps/index.html#//apple_ref/doc/uid/TP40014216-CH2-ID0
Using Swift with Cocoa and Objective-C
Bridging Header
Add Imports as you need them
Automatically generated by compiler
Generated Header
…using obj-c in swift…
…using swift in obj-c…
Optimize Obj-C for Swift
NS_ASSUME_NONNULL_BEGIN
nonnull|nullable|null_unspecified
NSArray<__kindof UIView *> *someViews;
https://developer.apple.com/videos/play/wwdc2015-401/
Try to avoid designing
Swift for Obj-C
You’ll have access to anything within a class or protocol that’s 

marked with the @objc attribute as long as it’s compatible with Objective-C. 

This excludes Swift-only features such as those listed here:
Generics
Tuples
Enumerations defined in Swift without Int raw value type
Structures defined in Swift
Top-level functions defined in Swift
Global variables defined in Swift
Typealiases defined in Swift
Swift-style variadics
Nested types
Curried functions
https://developer.apple.com/library/ios/documentation/Swift/
Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/
uid/TP40014216-CH10-ID122
Adding 

New 

Controller
Refactor
Existing
Controller1 2
Where to use Swift 

in the beginning?
It`s ok to build a parallel universe
Find New Solutions™
and yeah, use guard…
Swift will make
your life easier
title = ~"Select Title"
Custom Operator for i18n
struct Storyboard {
struct Segues {
static let channelInfo = "channelInfo"
}
struct Cells {
static let channelCell = "channelCell"
}
struct ReuseView {
static let sectionHeader = "header"
}
}
Swift will make
your life easier
Define Segues, Identifier, and so forth
Swift will make
your life easier
@IBOutlet weak var myCellView: UIView! {
didSet {
myCellView.backgroundColor = .redColor()
myCellView.layer.masksToBounds = true
myCellView.layer.cornerRadius = 2
}
}
Configure Views after outlet binding
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
switch (segue.identifier, segue.destinationViewController,
collectionView?.indexPathsForSelectedItems()?.first) {
case let(Storyboard.Segues.info?, controller as InfoController, index?):
controller.channel = channels?.get(index.row)
default:
break
}
}
Swift will make
your life easier
Pattern Match Your Life
Swift will make
your life easier
for (a, b) in (0...2).zipWithFollower() {
print(a, b) // 0,1 1,2 2,nil
}
public struct ZipWithFollower<T: SequenceType>: SequenceType {
public typealias Generator = AnyGenerator<(T.Generator.Element, T.Generator.Element?)>
let sequence: T
public init(_ sequence: T) {
self.sequence = sequence
}
public func generate() -> Generator {
var generator1 = sequence.generate()
var generator2 = sequence.generate()
_ = generator2.next()
return anyGenerator {
guard let element1 = generator1.next() else {
return nil
}
return (element1, generator2.next())
}
}
}
Clean up your control flow
struct StateFlow<S,T> {
let at: S
let to: T -> S
}
let wizardFlow: [StateFlow<WizardState, WizardConfig>] = [
from(.Init).to { config in
if config.useCustomSeletion {
return .ComponentWizard
}
return .ComponentSelection
}
]
Swift will make
your life easier
Double Down on Types
@elmkretzer
Go Swift!
www.symentis.com

Migrating Objective-C to Swift

  • 1.
    func migrating(from: ObjC)-> Swift! [objC autorelease]
  • 2.
  • 3.
  • 4.
  • 5.
    „…in future, allthe 
 nice things will only 
 come to swift…“ Apple Software Engineer
  • 6.
    What will youlose on the way?
  • 7.
    * [ ].h .m Good old Friends
  • 8.
    Runtime Dynamics NSInvocation NSMethodSignature [obj load] nilmessaging Macros https://developer.apple.com/swift/blog/?id=19
  • 9.
  • 10.
    Types Autoclosures Structs Generics Implicit Member Expressions CustomOperators Typealiases Enums Currying Recursive Enumerations Property ObserversProtocol Extensions Generators Subscripts Optionals Lazyness Pattern Matching Tuples Immutability ErrorType Access Control
  • 11.
    Simplicity view.backgroundColor = .redColor() [viewsetBackgroundColor: [UIColor redColor]]
  • 12.
    @warn_unused_result func flatMap<T> (@noescape_ transform: 
 (Self.Generator.Element) throws -> T?) 
 rethrows -> [T] Kinda Simplicity https://developer.apple.com/library/ios/documentation/Swift/Reference/ Swift_SequenceType_Protocol/index.html
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
    Existing Objective-C Project NoWarnings 😇 https://developer.apple.com/library/ios/documentation/Swift/Conceptual/ BuildingCocoaApps/index.html#//apple_ref/doc/uid/TP40014216-CH2-ID0 Using Swift with Cocoa and Objective-C
  • 18.
    Bridging Header Add Importsas you need them Automatically generated by compiler Generated Header …using obj-c in swift… …using swift in obj-c…
  • 19.
    Optimize Obj-C forSwift NS_ASSUME_NONNULL_BEGIN nonnull|nullable|null_unspecified NSArray<__kindof UIView *> *someViews; https://developer.apple.com/videos/play/wwdc2015-401/
  • 20.
    Try to avoiddesigning Swift for Obj-C You’ll have access to anything within a class or protocol that’s 
 marked with the @objc attribute as long as it’s compatible with Objective-C. 
 This excludes Swift-only features such as those listed here: Generics Tuples Enumerations defined in Swift without Int raw value type Structures defined in Swift Top-level functions defined in Swift Global variables defined in Swift Typealiases defined in Swift Swift-style variadics Nested types Curried functions https://developer.apple.com/library/ios/documentation/Swift/ Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/ uid/TP40014216-CH10-ID122
  • 21.
    Adding 
 New 
 Controller Refactor Existing Controller12 Where to use Swift 
 in the beginning? It`s ok to build a parallel universe
  • 22.
    Find New Solutions™ andyeah, use guard…
  • 23.
    Swift will make yourlife easier title = ~"Select Title" Custom Operator for i18n
  • 24.
    struct Storyboard { structSegues { static let channelInfo = "channelInfo" } struct Cells { static let channelCell = "channelCell" } struct ReuseView { static let sectionHeader = "header" } } Swift will make your life easier Define Segues, Identifier, and so forth
  • 25.
    Swift will make yourlife easier @IBOutlet weak var myCellView: UIView! { didSet { myCellView.backgroundColor = .redColor() myCellView.layer.masksToBounds = true myCellView.layer.cornerRadius = 2 } } Configure Views after outlet binding
  • 26.
    override func prepareForSegue(segue:UIStoryboardSegue, sender: AnyObject?) { switch (segue.identifier, segue.destinationViewController, collectionView?.indexPathsForSelectedItems()?.first) { case let(Storyboard.Segues.info?, controller as InfoController, index?): controller.channel = channels?.get(index.row) default: break } } Swift will make your life easier Pattern Match Your Life
  • 27.
    Swift will make yourlife easier for (a, b) in (0...2).zipWithFollower() { print(a, b) // 0,1 1,2 2,nil } public struct ZipWithFollower<T: SequenceType>: SequenceType { public typealias Generator = AnyGenerator<(T.Generator.Element, T.Generator.Element?)> let sequence: T public init(_ sequence: T) { self.sequence = sequence } public func generate() -> Generator { var generator1 = sequence.generate() var generator2 = sequence.generate() _ = generator2.next() return anyGenerator { guard let element1 = generator1.next() else { return nil } return (element1, generator2.next()) } } } Clean up your control flow
  • 28.
    struct StateFlow<S,T> { letat: S let to: T -> S } let wizardFlow: [StateFlow<WizardState, WizardConfig>] = [ from(.Init).to { config in if config.useCustomSeletion { return .ComponentWizard } return .ComponentSelection } ] Swift will make your life easier Double Down on Types
  • 29.