SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

SAML VS OAuth 2.0 VS OpenID Connect
SAML VS OAuth 2.0 VS OpenID ConnectSAML VS OAuth 2.0 VS OpenID Connect
SAML VS OAuth 2.0 VS OpenID ConnectUbisecure
 
Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)Postman
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.Questpond
 
An Introduction to OAuth 2
An Introduction to OAuth 2An Introduction to OAuth 2
An Introduction to OAuth 2Aaron Parecki
 
Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)
Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)
Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)Svetlin Nakov
 
Node.js Event Emitter
Node.js Event EmitterNode.js Event Emitter
Node.js Event EmitterEyal Vardi
 
Token, token... From SAML to OIDC
Token, token... From SAML to OIDCToken, token... From SAML to OIDC
Token, token... From SAML to OIDCShiu-Fun Poon
 
Build RESTful API Using Express JS
Build RESTful API Using Express JSBuild RESTful API Using Express JS
Build RESTful API Using Express JSCakra Danu Sedayu
 
cloud computing Syllabus.docx
cloud computing Syllabus.docxcloud computing Syllabus.docx
cloud computing Syllabus.docxFarhanaMariyam1
 
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.Mikhail Egorov
 
OpenID Connect vs. OpenID 1 & 2
OpenID Connect vs. OpenID 1 & 2OpenID Connect vs. OpenID 1 & 2
OpenID Connect vs. OpenID 1 & 2Mike Schwartz
 
Living the Stream Dream with Pulsar and Spring Boot
Living the Stream Dream with Pulsar and Spring BootLiving the Stream Dream with Pulsar and Spring Boot
Living the Stream Dream with Pulsar and Spring BootTimothy Spann
 
Amazon API Gateway
Amazon API GatewayAmazon API Gateway
Amazon API GatewayMark Bate
 
XML & XPath Injections
XML & XPath InjectionsXML & XPath Injections
XML & XPath InjectionsAMol NAik
 

Tendances (20)

SAML VS OAuth 2.0 VS OpenID Connect
SAML VS OAuth 2.0 VS OpenID ConnectSAML VS OAuth 2.0 VS OpenID Connect
SAML VS OAuth 2.0 VS OpenID Connect
 
Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)
 
OAuth 2.0
OAuth 2.0OAuth 2.0
OAuth 2.0
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.
 
Python-DataAbstarction.pptx
Python-DataAbstarction.pptxPython-DataAbstarction.pptx
Python-DataAbstarction.pptx
 
An Introduction to OAuth 2
An Introduction to OAuth 2An Introduction to OAuth 2
An Introduction to OAuth 2
 
Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)
Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)
Cryptography for Java Developers: Nakov jProfessionals (Jan 2019)
 
Node.js Event Emitter
Node.js Event EmitterNode.js Event Emitter
Node.js Event Emitter
 
Token, token... From SAML to OIDC
Token, token... From SAML to OIDCToken, token... From SAML to OIDC
Token, token... From SAML to OIDC
 
Build RESTful API Using Express JS
Build RESTful API Using Express JSBuild RESTful API Using Express JS
Build RESTful API Using Express JS
 
cloud computing Syllabus.docx
cloud computing Syllabus.docxcloud computing Syllabus.docx
cloud computing Syllabus.docx
 
JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
 
WCF
WCFWCF
WCF
 
C# REST API
C# REST APIC# REST API
C# REST API
 
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
What’s wrong with WebSocket APIs? Unveiling vulnerabilities in WebSocket APIs.
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
OpenID Connect vs. OpenID 1 & 2
OpenID Connect vs. OpenID 1 & 2OpenID Connect vs. OpenID 1 & 2
OpenID Connect vs. OpenID 1 & 2
 
Living the Stream Dream with Pulsar and Spring Boot
Living the Stream Dream with Pulsar and Spring BootLiving the Stream Dream with Pulsar and Spring Boot
Living the Stream Dream with Pulsar and Spring Boot
 
Amazon API Gateway
Amazon API GatewayAmazon API Gateway
Amazon API Gateway
 
XML & XPath Injections
XML & XPath InjectionsXML & XPath Injections
XML & XPath Injections
 

Similaire à Migrating from Objective-C to Swift

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
 

Similaire à Migrating from Objective-C to Swift (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
 

Dernier

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
 
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
 
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
 
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
 
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
 
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
 

Dernier (7)

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
 
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
 
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
 
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,
 
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
 
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
 

Migrating from Objective-C to Swift