SlideShare ist ein Scribd-Unternehmen logo
1 von 64
CASE STUDY: MIGRATING
FROM OBJECTIVE-C TO SWIFT
DOMINIQUE STRANZ
MIGRATE 

TO SWIFT
STAY WITH
OBJECTIVE-C
?
WE DECIDED TO
MIGRATE 🎉
CUI BONO?
Lucius Cassius Longinus
DEVELOPERS
STRING
INTERPOLATION
OPTIONALS
TUPLES
STRING ENUMS
NO MORE 

HEADER FILES
PROTOCOLS

EXTENSIONS
and so on, 

and so forth…
HOW DO

I START?
Application
Configuration

Manager
API Client
Utils
Application
Configuration

Manager
new API Client
Utils
Application
new API Client
Utils
Adopt Nullability
Configuration

Manager
Adopt Nullability
Configuration

Manager
Adopt Nullability
Configuration

Manager
Adopt Nullability
Configuration

Manager
Application
new API Client
Utils
Adopt Nullability
Configuration

Manager
ALL NEW
FEATURES
WRITTEN 

IN SWIFT
USE „TECH DAYS”
TO MIGRATE 

OBJECTIVE-C
CODE 

34%
of code in
after 2 months
53%
of code in
now
3 RULES OF
EFFECTIVE
MIGRATION
FILE BY FILE
MIGRATION 

IS THE MOST
EFFECTIVE WAYChild2
Base
Child1
Class2
Class4
Class3
START WITH 

FILES WITHOUT
SUBCLASSES
Child2
Base
Child1
Class2
Class4
Class3
YOU CANNOT SUBCLASS
A SWIFT CLASS IN
OBJECTIVE-C
SWIFT CLASS MUST BE
A DESCENDANT OF AN
OBJECTIVE-C CLASS

…TO BE ACCESSIBLE
IN OBJECTIVE-C FILES
Child2
Base
Child1
Class4
Class3
NSObject
SWIFT CLASS MUST BE
A DESCENDANT OF AN
OBJECTIVE-C CLASS

Child2
Base
Child1
Class4
Class3
NSObject
OBJECTIVE-C WILL NOT BE
ABLE TO TRANSLATE CERTAIN
SWIFT-SPECIFIC FEATURES


MIXED PROJECTS
Mix-and-match functionality makes it easy to choose
which features and functionality to implement in
Swift, and which to leave in Objective-C.
Interoperability makes it possible to integrate those
features back into Objective-C code with no hassle.
Apple Inc. “Using Swift with Cocoa and Objective-C (Swift 3).”
BUNDLE SIZE
22 MB 38 MB
YES FOR THE WATCHOS APP
NO FOR THE WATCHOS APP EXTENSION
Always Embed Swift Standard Libraries
⌚
CODE AUTOCOMPLETION
FIXED IN XCODE 8.3
IMPORTS
IN OBJECTIVE-C
HEADER FILES ONLY
USE FORWARD
DECLARATIONS
NSObject
@class ClassName;
@protocol ProtocolName;
IMPORTING A SWIFT HEADER FILE
THERE WILL LEAVE YOU WITH
A CIRCULAR REFERENCE.
IF BOTH SWIFT AND
OBJECTIVE-C CLASSES
ARE IN THE SAME
APPLICATION PROJECT
NSObject
#import "ModuleName-Swift.h"
IF BOTH SWIFT AND
OBJECTIVE-C CLASSES
ARE IN THE SAME
COCOA POD PROJECT
NSObject
#import <PodName/PodName-Swift.h>
IF SWIFT FILE IS 

IN ANOTHER POD
NSObject
@import PodName;
IF SWIFT FILE IS 

IN ANOTHER POD
NSObject
@import PodName;
ADD *.SWIFT FILES TO
SOURCE_FILES DECLARATION 

IN PODSPEC FILE
SWIFT CLASS 

IN OBJECTIVE-C
MUST BE A DESCENDANT 

OF AN OBJECTIVE-C CLASS
WILL NOT BE VISIBLE

IN OBJECTIVE-C
INT?, INT!, FLOAT?, …
SOME NAMES ARE ALREADY IN
USE IN NSOBJECT
description: String
SWIFT CLASSES CANNOT BE
SUBCLASSED IN OBJECTIVE-C
objc_subclassing_restricted
METHODS WITH NIL
TERMINATION WILL BE NOT
ACCESSIBLE IN SWIFT
NS_REQUIRES_NIL_TERMINATION
DEALLOC IS UNAVAILABLE 

IN SWIFT, BUT YOU CAN USE
DEINIT INSTEAD
dealloc != deinit
SWIFT ENUM 

IN OBJECTIVE-C
ENUM SHOULD HAVE THE
@OBJC PREFIX
@objc prefix
ASSOCIATED VALUES 

ARE NOT SUPPORTED
case variant1(value: Int)
IN OBJECTIVE-C ENUM CAN
ONLY HAVE INTEGER TYPE
@enum Name: Int
CASE STUDY: MIGRATING FROM OBJECTIVE-C TO SWIFT
RawRepresentable enum for ObjectMapper?
▸ Model should provide wrapper for Obj-C code:
▸ Translation to enum: Int 

during mapping transformation or in runtime
▸ Computed property `isActive: Bool`, `is…: Bool`
CASE STUDY: MIGRATING FROM OBJECTIVE-C TO SWIFT
API Endpoints as URLRequestConvertible enums?
▸ Create a proxy class (inherited from NSObject) with class
requests methods, that inside will use Swift enum
▸ We decided to only define methods really used by Obj-C











More about elegant API Endpoints in Alamofire

https://github.com/Alamofire/Alamofire#crud--authorization
WHAT WILL 

NSCODER 

FAIL TO SEE?
CASE STUDY: MIGRATING FROM OBJECTIVE-C TO SWIFT
NSCoding
▸ NSKeyedArchiver, NSKeyedUnarchiver will see only
properties visible for Objective-C
▸ We can change properties type or…
CASE STUDY: MIGRATING FROM OBJECTIVE-C TO SWIFT
NSCoding
▸ NSKeyedArchiver, NSKeyedUnarchiver will see only
properties visible for Objective-C
▸ We can change properties type or…
▸ Use value(forUndefinedKey key: String) -> Any? and
setValue(_ value: Any?, forUndefinedKey key: String)

to set/get not bridged properties
▸ Example: Use enum’s rawValue as encodable value
CASE STUDY: MIGRATING FROM OBJECTIVE-C TO SWIFT
NSCoding
CASE STUDY: MIGRATING FROM OBJECTIVE-C TO SWIFT
Future? Swift Archival & Serialization proposal
▸ It aims to provide a solution for the archival of Swift struct
and enum types
▸ It aims to provide a more type-safe solution for serializing
to external formats, such as JSON and plist
▸ Read more: https://github.com/itaiferber/swift-evolution/
blob/swift-archival-serialization/proposals/XXXX-swift-
archival-serialization.md
USING 

ENUMERATIONS
AS ERRORS
CASE STUDY: MIGRATING FROM OBJECTIVE-C TO SWIFT
enum ServiceError: Error {}
CASE STUDY: MIGRATING FROM OBJECTIVE-C TO SWIFT
enum ServiceError: Error {}
▸ Error type in Obj-C code? 

NSError without associated values…
CASE STUDY: MIGRATING FROM OBJECTIVE-C TO SWIFT
enum ServiceError: Error {}
▸ Error type in Obj-C code? 

NSError without associated values…
▸ CustomNSError protocol: Describes an error type that
specifically provides a domain, code, and user-info
dictionary





More: https://github.com/apple/swift-evolution/blob/
master/proposals/0112-nserror-bridging.md
CASE STUDY: MIGRATING FROM OBJECTIVE-C TO SWIFT
enum ServiceError: Error {}
CASE STUDY: MIGRATING FROM OBJECTIVE-C TO SWIFT
enum ServiceError: Error {}
LESSONS
LEARNED
CASE STUDY: MIGRATING FROM OBJECTIVE-C TO SWIFT
Optional(„2000 PLN”)
CASE STUDY: MIGRATING FROM OBJECTIVE-C TO SWIFT
Optional(„2000 PLN”)
▸ Swift 3.1 will actually actually raise 

a warning when you use an optional 

in string interpolation













More: https://oleb.net/blog/2016/12/optionals-string-
interpolation
CASE STUDY: MIGRATING FROM OBJECTIVE-C TO SWIFT
APNS token == „32bytes”
read more at tech.olx.com
THANK YOU

Weitere ähnliche Inhalte

Was ist angesagt?

ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewShahed Chowdhuri
 
Angular Pipes Workshop
Angular Pipes WorkshopAngular Pipes Workshop
Angular Pipes WorkshopNir Kaufman
 
Selenium IDE Tutorial For Beginners | Selenium IDE Tutorial | What Is Seleniu...
Selenium IDE Tutorial For Beginners | Selenium IDE Tutorial | What Is Seleniu...Selenium IDE Tutorial For Beginners | Selenium IDE Tutorial | What Is Seleniu...
Selenium IDE Tutorial For Beginners | Selenium IDE Tutorial | What Is Seleniu...Simplilearn
 
Working with Dynamic Content and Adding Templating engines, MVC
Working with Dynamic Content and Adding Templating engines, MVCWorking with Dynamic Content and Adding Templating engines, MVC
Working with Dynamic Content and Adding Templating engines, MVCKnoldus Inc.
 
What Is Express JS?
What Is Express JS?What Is Express JS?
What Is Express JS?Simplilearn
 
Chapter 18: Transitions, Transforms, and Animation
Chapter 18: Transitions, Transforms, and AnimationChapter 18: Transitions, Transforms, and Animation
Chapter 18: Transitions, Transforms, and AnimationSteve Guinan
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic FunctionsWebStackAcademy
 
ASP.NET - Life cycle of asp
ASP.NET - Life cycle of aspASP.NET - Life cycle of asp
ASP.NET - Life cycle of asppriya Nithya
 
Introduction to react native
Introduction to react nativeIntroduction to react native
Introduction to react nativeDani Akash
 
An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)iFour Technolab Pvt. Ltd.
 
Tutoriel tortoise svn
Tutoriel tortoise svnTutoriel tortoise svn
Tutoriel tortoise svnWinslo Nwan
 
Node.js File system & Streams
Node.js File system & StreamsNode.js File system & Streams
Node.js File system & StreamsEyal Vardi
 

Was ist angesagt? (20)

ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with Overview
 
Angular Pipes Workshop
Angular Pipes WorkshopAngular Pipes Workshop
Angular Pipes Workshop
 
Selenium IDE Tutorial For Beginners | Selenium IDE Tutorial | What Is Seleniu...
Selenium IDE Tutorial For Beginners | Selenium IDE Tutorial | What Is Seleniu...Selenium IDE Tutorial For Beginners | Selenium IDE Tutorial | What Is Seleniu...
Selenium IDE Tutorial For Beginners | Selenium IDE Tutorial | What Is Seleniu...
 
Working with Dynamic Content and Adding Templating engines, MVC
Working with Dynamic Content and Adding Templating engines, MVCWorking with Dynamic Content and Adding Templating engines, MVC
Working with Dynamic Content and Adding Templating engines, MVC
 
What Is Express JS?
What Is Express JS?What Is Express JS?
What Is Express JS?
 
7.data types in c#
7.data types in c#7.data types in c#
7.data types in c#
 
Modern JS with ES6
Modern JS with ES6Modern JS with ES6
Modern JS with ES6
 
Chapter 18: Transitions, Transforms, and Animation
Chapter 18: Transitions, Transforms, and AnimationChapter 18: Transitions, Transforms, and Animation
Chapter 18: Transitions, Transforms, and Animation
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
 
TypeScript VS JavaScript.pptx
TypeScript VS JavaScript.pptxTypeScript VS JavaScript.pptx
TypeScript VS JavaScript.pptx
 
Maven
MavenMaven
Maven
 
ASP.NET - Life cycle of asp
ASP.NET - Life cycle of aspASP.NET - Life cycle of asp
ASP.NET - Life cycle of asp
 
Introduction to react native
Introduction to react nativeIntroduction to react native
Introduction to react native
 
Angular
AngularAngular
Angular
 
An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)
 
Selenium
SeleniumSelenium
Selenium
 
Tutoriel tortoise svn
Tutoriel tortoise svnTutoriel tortoise svn
Tutoriel tortoise svn
 
Selenium IDE
Selenium IDESelenium IDE
Selenium IDE
 
Angular
AngularAngular
Angular
 
Node.js File system & Streams
Node.js File system & StreamsNode.js File system & Streams
Node.js File system & Streams
 

Ähnlich wie Migrate to Swift from Objective-C

Getting Swifty in an Objective-C World
Getting Swifty in an Objective-C WorldGetting Swifty in an Objective-C World
Getting Swifty in an Objective-C WorldJason Grandelli
 
21st Docker Switzerland Meetup - ISTIO
21st Docker Switzerland Meetup - ISTIO21st Docker Switzerland Meetup - ISTIO
21st Docker Switzerland Meetup - ISTIONiklaus Hirt
 
Managing microservices with istio on OpenShift - Meetup
Managing microservices with istio on OpenShift - MeetupManaging microservices with istio on OpenShift - Meetup
Managing microservices with istio on OpenShift - MeetupJosé Román Martín Gil
 
Serhiy Kalinets "Building Service Mesh with .NET Core"
Serhiy Kalinets "Building Service Mesh with .NET Core"Serhiy Kalinets "Building Service Mesh with .NET Core"
Serhiy Kalinets "Building Service Mesh with .NET Core"Fwdays
 
Framework Agnostic Discovery
Framework Agnostic DiscoveryFramework Agnostic Discovery
Framework Agnostic DiscoveryKubeAcademy
 
Introduction to c_plus_plus
Introduction to c_plus_plusIntroduction to c_plus_plus
Introduction to c_plus_plusSayed Ahmed
 
Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)Sayed Ahmed
 
Newspeak: Evolving Smalltalk for the Age of the Net
Newspeak: Evolving Smalltalk for the Age of the NetNewspeak: Evolving Smalltalk for the Age of the Net
Newspeak: Evolving Smalltalk for the Age of the NetESUG
 
What Makes Objective C Dynamic?
What Makes Objective C Dynamic?What Makes Objective C Dynamic?
What Makes Objective C Dynamic?Kyle Oba
 
Deploy Application on Kubernetes
Deploy Application on KubernetesDeploy Application on Kubernetes
Deploy Application on KubernetesOpsta
 
Difference between Java and c#
Difference between Java and c#Difference between Java and c#
Difference between Java and c#Sagar Pednekar
 
Cling the llvm based interpreter
Cling the llvm based interpreterCling the llvm based interpreter
Cling the llvm based interpreterRoberto Nogueira
 

Ähnlich wie Migrate to Swift from Objective-C (20)

Swift vs Objective-C
Swift vs Objective-CSwift vs Objective-C
Swift vs Objective-C
 
Getting Swifty in an Objective-C World
Getting Swifty in an Objective-C WorldGetting Swifty in an Objective-C World
Getting Swifty in an Objective-C World
 
21st Docker Switzerland Meetup - ISTIO
21st Docker Switzerland Meetup - ISTIO21st Docker Switzerland Meetup - ISTIO
21st Docker Switzerland Meetup - ISTIO
 
L03 Software Design
L03 Software DesignL03 Software Design
L03 Software Design
 
Managing microservices with istio on OpenShift - Meetup
Managing microservices with istio on OpenShift - MeetupManaging microservices with istio on OpenShift - Meetup
Managing microservices with istio on OpenShift - Meetup
 
Shift Dev Conf API
Shift Dev Conf APIShift Dev Conf API
Shift Dev Conf API
 
Serhiy Kalinets "Building Service Mesh with .NET Core"
Serhiy Kalinets "Building Service Mesh with .NET Core"Serhiy Kalinets "Building Service Mesh with .NET Core"
Serhiy Kalinets "Building Service Mesh with .NET Core"
 
Framework Agnostic Discovery
Framework Agnostic DiscoveryFramework Agnostic Discovery
Framework Agnostic Discovery
 
java vs C#
java vs C#java vs C#
java vs C#
 
Introduction to c_plus_plus
Introduction to c_plus_plusIntroduction to c_plus_plus
Introduction to c_plus_plus
 
Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)Introduction to c_plus_plus (6)
Introduction to c_plus_plus (6)
 
Kotlin
KotlinKotlin
Kotlin
 
Newspeak: Evolving Smalltalk for the Age of the Net
Newspeak: Evolving Smalltalk for the Age of the NetNewspeak: Evolving Smalltalk for the Age of the Net
Newspeak: Evolving Smalltalk for the Age of the Net
 
What Makes Objective C Dynamic?
What Makes Objective C Dynamic?What Makes Objective C Dynamic?
What Makes Objective C Dynamic?
 
Deploy Application on Kubernetes
Deploy Application on KubernetesDeploy Application on Kubernetes
Deploy Application on Kubernetes
 
SRAVANByCPP
SRAVANByCPPSRAVANByCPP
SRAVANByCPP
 
C++ programing lanuage
C++ programing lanuageC++ programing lanuage
C++ programing lanuage
 
Difference between Java and c#
Difference between Java and c#Difference between Java and c#
Difference between Java and c#
 
Cling the llvm based interpreter
Cling the llvm based interpreterCling the llvm based interpreter
Cling the llvm based interpreter
 
Lecture02
Lecture02Lecture02
Lecture02
 

Kürzlich hochgeladen

Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPsychicRuben LoveSpells
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRnishacall1
 
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceDelhi Call girls
 
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Pooja Nehwal
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceanilsa9823
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7Pooja Nehwal
 
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceanilsa9823
 

Kürzlich hochgeladen (7)

Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost LoverPowerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
 
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 71 Noida Escorts >༒8448380779 Escort Service
 
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
Call US Pooja 9892124323 ✓Call Girls In Mira Road ( Mumbai ) secure service,
 
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Gomti Nagar Lucknow best Night Fun service
 
9892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x79892124323 | Book Call Girls in Juhu and escort services 24x7
9892124323 | Book Call Girls in Juhu and escort services 24x7
 
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Saharaganj Lucknow best sexual service
 

Migrate to Swift from Objective-C