SlideShare a Scribd company logo
Getting Swifty in an
Objective-C World
ENGINEERING
Jason Grandelli // Mobile Engineering Manager @ URBN, inc
The Situation
• 9 engineers, ~8 Obj-C apps, ~6 Obj-C shared frameworks
• 100’s of thousands of lines of Obj-C
• Swift matures with 2.0
• New features, production timelines
• Decision time - pull the trigger on Swift or fall behind!
• Our path to Swifty was paved with good intentions
Swift vs Objective-C
• Obj-C > 30 yrs old, Swift 2 years old
• Dynamic vs Static
• Superset of C vs Best bits of everything
• Support for modern features such as tuples, optionals, simplified
file structure, access modifiers, generics, functional bits
• Mostly full interoperability, kind of
#codeFight #holyWar #changeIsHard
Interop
• Swift.h & Bridging-Header.h
• @objc to explicitly declare availability
• Add support for nullability & generics to make your Obj-C more
predictable
#itJustWorks
NS_ASSUME_NONNULL_BEGIN
…
NS_ASSUME_NONNULL_END
@property (nonatomic, copy) NSArray<NSString *> * _Nullable items;
@property (nonatomic, copy) NSString * _Nonnull title;
- (NSURL * _Nullable)urlFromString:(NSString * _Nonnull)name;
Interop is Hard
All of the coolest features don’t bridge 😢
• Generics
• Tuples
• Enums defined in Swift
• Structs defined in Swift
• Top-level functions defined in Swift
• Global variables defined in Swift
• Typealiases defined in Swift
• Swift-style variadics
• Nested types
• Objective-C can’t inherit from Swift types
Or screw it lets burn it all to the ground and start over.
Shim All The Things
• Dope new features or Legacy Support? False Dichotomy.
• Priority is to learn & use Swift as the creators intended
• Writing Objective-C styled Swift is a waste of time
• New Swift code should be free of debt
• No time to start over with 100% Swift
• Enter shims to keep us Swifty and appease our Obj-C captors
Exhibit A
enum LocalizedStrings: String {
case wishlist_home_button_title
case customer_service_phone_number
case credit_card_scan_flash_on
case credit_card_scan_flash_off
}
func localized(string string: LocalizedStrings) -> String {
return NSLocalizedString(string.rawValue, comment: string.rawValue)
}
class CompatLocalization: NSObject {
@objc static func wishlistHomeButtonTitle() -> String {
return localized(string: .wishlist_home_button_title)
}
@objc static func customerServicePhoneNumber() -> String {
return localized(string: .customer_service_phone_number)
}
@objc static func creditCardScanOn() -> String {
return localized(string: .credit_card_scan_flash_on)
}
@objc static func creditCardScanOff() -> String {
return localized(string: .credit_card_scan_flash_off)
}
}
...
[CompatLocalization wishlistHomeButtonTitle]
[CompatLocalization customerServicePhoneNumber]
[CompatLocalization creditCardScanOn]
[CompatLocalization creditCardScanOff]
String backed enums and global functions oh my
Enum backed
by string
Global Function
Obj-C Bridgeable class
w/ static functions
Obj-C interacting w/ static
compat functions
Exhibit B
protocol AnalyticsCollection {
func sendEvent()
}
enum AnalyticsEvent {
enum Global: AnalyticsCollection {
case AppLaunchedFromSpotlight(activityURL: String)
case AppLaunchedFromUniversalLink(activityURL: String
func sendEvent() { ... }
}
}
...
class ANTAnalytics : NSObject, UCOAnalyticsProvider { ... }
extension ANTAnalytics {
func logAppLaunchedFromSpotlight(activityURL: String) {
AnalyticsEvent.Global.AppLaunchedFromSpotlight(activityURL: activityURL).sendEvent()
}
func logAppLaunchedFromUniversalLink(activityURL: String) {
AnalyticsEvent.Global.AppLaunchedFromUniversalLink(activityURL: activityURL).sendEvent()
}
}
...
[[ANTAnalytics sharedInstance] logAppLaunchedFromUniversalLink:activityURL];
[[ANTAnalytics sharedInstance] logAppLaunchedFromSpotlight:activityURL];
Nested types, enums that conform to a protocol & have functions
Enum without backing value,
conforming to protocol,
with function
Extension on Obj-C
bridgeable type
Obj-C interacting w/ compat
functions
Where are they now?
• Every app now contains between 5-20+%
• 1 app 100% swift
• New shared frameworks all in swift
• All Objective-C updated to better work with Swift
• Slowly but surely gettin rid of the Objective-C
We got Swifty!
Questions?
ENGINEERING
github.com/urbn
jgrandelli@urbn.com
@jasongrandelli

More Related Content

PPTX
Swift vs Objective-C
PDF
A Journey From Objective C to Swift - Chromeinfotech
ODP
Objectivec vs swift
PDF
iOS NSAgora #3: Objective-C vs. Swift
PDF
Intuitive CLIs for gRPC APIs
PPTX
Code for kombol - Objects and Functions in JS and NodeJS
KEY
iOS Einführung am Beispiel von play NEXT TEE
PPTX
Javascript ES6
Swift vs Objective-C
A Journey From Objective C to Swift - Chromeinfotech
Objectivec vs swift
iOS NSAgora #3: Objective-C vs. Swift
Intuitive CLIs for gRPC APIs
Code for kombol - Objects and Functions in JS and NodeJS
iOS Einführung am Beispiel von play NEXT TEE
Javascript ES6

What's hot (6)

PDF
CocoaHeads Paris - CATransaction: What the flush?!
PDF
No More, No Less: A Formal Model for Serverless Computing
PPTX
built in function
ODP
Elixir and elm - the perfect couple
PPTX
Chaos Testing with F# and Azure by Rachel Reese at Codemotion Dubai
KEY
CocoaHeads Toulouse - Guillaume Cerquant - UIView
CocoaHeads Paris - CATransaction: What the flush?!
No More, No Less: A Formal Model for Serverless Computing
built in function
Elixir and elm - the perfect couple
Chaos Testing with F# and Azure by Rachel Reese at Codemotion Dubai
CocoaHeads Toulouse - Guillaume Cerquant - UIView
Ad

Similar to Getting Swifty in an Objective-C World (20)

PDF
Bringing Swift into your Objective-C Projects
PDF
Migrating from Objective-C to Swift
PDF
Swift, swiftly
PDF
Swift for-rubyists
PDF
Facilitating Idiomatic Swift with Objective-C
PPTX
Swift LA Meetup at eHarmony- Swift and Enterprise and eHarmony with Heena Ras...
PDF
WWDC 2014 Recap & Swift Introduction
PDF
Protocols promised-land-2
PDF
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applications
PPT
Swift: Apple's New Programming Language for iOS and OS X
PDF
SV-ios-objc-to-swift
PDF
Swift, a quick overview
PDF
Swiftのこれまでの動向のまとめと 今後のさらなる発展の期待 - iOSDC 2016
PDF
Intro to iOS Development • Made by Many
PDF
Working with Cocoa and Objective-C
PDF
Uri Nachmias - Adopting Swift @Houzz - The good, the bad and the ugly
PDF
Swiftly Switching: The Transition from Obj-C to Swift
PDF
Cocoa Design Patterns in Swift
PDF
iOS for Android Developers (with Swift)
Bringing Swift into your Objective-C Projects
Migrating from Objective-C to Swift
Swift, swiftly
Swift for-rubyists
Facilitating Idiomatic Swift with Objective-C
Swift LA Meetup at eHarmony- Swift and Enterprise and eHarmony with Heena Ras...
WWDC 2014 Recap & Swift Introduction
Protocols promised-land-2
Hack in the Box GSEC 2016 - Reverse Engineering Swift Applications
Swift: Apple's New Programming Language for iOS and OS X
SV-ios-objc-to-swift
Swift, a quick overview
Swiftのこれまでの動向のまとめと 今後のさらなる発展の期待 - iOSDC 2016
Intro to iOS Development • Made by Many
Working with Cocoa and Objective-C
Uri Nachmias - Adopting Swift @Houzz - The good, the bad and the ugly
Swiftly Switching: The Transition from Obj-C to Swift
Cocoa Design Patterns in Swift
iOS for Android Developers (with Swift)
Ad

Recently uploaded (20)

PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
L1 - Introduction to python Backend.pptx
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
ai tools demonstartion for schools and inter college
PDF
Nekopoi APK 2025 free lastest update
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Essential Infomation Tech presentation.pptx
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Introduction to Artificial Intelligence
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
How Creative Agencies Leverage Project Management Software.pdf
L1 - Introduction to python Backend.pptx
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Reimagine Home Health with the Power of Agentic AI​
Upgrade and Innovation Strategies for SAP ERP Customers
Wondershare Filmora 15 Crack With Activation Key [2025
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
ai tools demonstartion for schools and inter college
Nekopoi APK 2025 free lastest update
How to Choose the Right IT Partner for Your Business in Malaysia
Essential Infomation Tech presentation.pptx
wealthsignaloriginal-com-DS-text-... (1).pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
2025 Textile ERP Trends: SAP, Odoo & Oracle
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Introduction to Artificial Intelligence
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)

Getting Swifty in an Objective-C World

  • 1. Getting Swifty in an Objective-C World ENGINEERING Jason Grandelli // Mobile Engineering Manager @ URBN, inc
  • 2. The Situation • 9 engineers, ~8 Obj-C apps, ~6 Obj-C shared frameworks • 100’s of thousands of lines of Obj-C • Swift matures with 2.0 • New features, production timelines • Decision time - pull the trigger on Swift or fall behind! • Our path to Swifty was paved with good intentions
  • 3. Swift vs Objective-C • Obj-C > 30 yrs old, Swift 2 years old • Dynamic vs Static • Superset of C vs Best bits of everything • Support for modern features such as tuples, optionals, simplified file structure, access modifiers, generics, functional bits • Mostly full interoperability, kind of #codeFight #holyWar #changeIsHard
  • 4. Interop • Swift.h & Bridging-Header.h • @objc to explicitly declare availability • Add support for nullability & generics to make your Obj-C more predictable #itJustWorks NS_ASSUME_NONNULL_BEGIN … NS_ASSUME_NONNULL_END @property (nonatomic, copy) NSArray<NSString *> * _Nullable items; @property (nonatomic, copy) NSString * _Nonnull title; - (NSURL * _Nullable)urlFromString:(NSString * _Nonnull)name;
  • 5. Interop is Hard All of the coolest features don’t bridge 😢 • Generics • Tuples • Enums defined in Swift • Structs defined in Swift • Top-level functions defined in Swift • Global variables defined in Swift • Typealiases defined in Swift • Swift-style variadics • Nested types • Objective-C can’t inherit from Swift types Or screw it lets burn it all to the ground and start over.
  • 6. Shim All The Things • Dope new features or Legacy Support? False Dichotomy. • Priority is to learn & use Swift as the creators intended • Writing Objective-C styled Swift is a waste of time • New Swift code should be free of debt • No time to start over with 100% Swift • Enter shims to keep us Swifty and appease our Obj-C captors
  • 7. Exhibit A enum LocalizedStrings: String { case wishlist_home_button_title case customer_service_phone_number case credit_card_scan_flash_on case credit_card_scan_flash_off } func localized(string string: LocalizedStrings) -> String { return NSLocalizedString(string.rawValue, comment: string.rawValue) } class CompatLocalization: NSObject { @objc static func wishlistHomeButtonTitle() -> String { return localized(string: .wishlist_home_button_title) } @objc static func customerServicePhoneNumber() -> String { return localized(string: .customer_service_phone_number) } @objc static func creditCardScanOn() -> String { return localized(string: .credit_card_scan_flash_on) } @objc static func creditCardScanOff() -> String { return localized(string: .credit_card_scan_flash_off) } } ... [CompatLocalization wishlistHomeButtonTitle] [CompatLocalization customerServicePhoneNumber] [CompatLocalization creditCardScanOn] [CompatLocalization creditCardScanOff] String backed enums and global functions oh my Enum backed by string Global Function Obj-C Bridgeable class w/ static functions Obj-C interacting w/ static compat functions
  • 8. Exhibit B protocol AnalyticsCollection { func sendEvent() } enum AnalyticsEvent { enum Global: AnalyticsCollection { case AppLaunchedFromSpotlight(activityURL: String) case AppLaunchedFromUniversalLink(activityURL: String func sendEvent() { ... } } } ... class ANTAnalytics : NSObject, UCOAnalyticsProvider { ... } extension ANTAnalytics { func logAppLaunchedFromSpotlight(activityURL: String) { AnalyticsEvent.Global.AppLaunchedFromSpotlight(activityURL: activityURL).sendEvent() } func logAppLaunchedFromUniversalLink(activityURL: String) { AnalyticsEvent.Global.AppLaunchedFromUniversalLink(activityURL: activityURL).sendEvent() } } ... [[ANTAnalytics sharedInstance] logAppLaunchedFromUniversalLink:activityURL]; [[ANTAnalytics sharedInstance] logAppLaunchedFromSpotlight:activityURL]; Nested types, enums that conform to a protocol & have functions Enum without backing value, conforming to protocol, with function Extension on Obj-C bridgeable type Obj-C interacting w/ compat functions
  • 9. Where are they now? • Every app now contains between 5-20+% • 1 app 100% swift • New shared frameworks all in swift • All Objective-C updated to better work with Swift • Slowly but surely gettin rid of the Objective-C We got Swifty!