SlideShare a Scribd company logo
1 of 16
Swift & Enterprise & eHarmony
• Why?
• Bridging & Migration
• eHarmony’s Plan to Tackle
• Simpler to read
• Type safety and hence code safety
• Interacts with Objective-C Runtime seamlessly
• Take advantage of Objective-C APIs and Cocoa design patterns
• Open Source - we gain flexibility and freedom
• Other platforms can also adopt Swift
Why?
3 important aspects of Swift / Objective-C compatibility:
• Interoperability
Ability to interface between Swift and Objective-C in either direction
• Mix and Match
Allows you to create mixed-language apps containing both Swift and
Objective-C files that can communicate with each other
• Migration
Migration from existing Objective-C code to Swift is made easy with
interoperability and mix and match, making it possible to replace parts
of your Objective-C apps with the latest Swift features
Bridging & Migration
3 New features introduced for Objective-C :
• Nullability for Objective-C
• Lightweight Generics
• Kind of
Bridging & Migration
Bridging & Migration
Objective-C
@interface SNGFeedView
@property(nonatomic, readonly) UIView *photoView;
@property(nonatomic, readonly, copy) NSArray *feedViews;
- (UIView*) photoViewForFeed:(SSFeed) photoFeed;
@end
Swift
class SNGFeedView {
var photoView : UIView?
var feedViews: [AnyObject]!
func photoView(photoFeed:SSFeed) - > UIView
}
Indicate whether Objective-C/C pointers can be nil
• Better communicate intent of APIs
• Allows improved static checking
• Improves usability of APIs in Swift
Nullability
Nullability Qualifiers
Nullability
Qualifier Usage Swift
nullable Pointer may be nil UIView?
nonnull nil is not a meaningful value UIView
null_unspecified Neither nullable nor nonnull
applies
UIView!
NOTE: Compiler does not change the way it generates
code because of a non-null annotation.
Example:
NS_ASSUME_NONNULL_BEGIN
@interface SNGFeedView
@property(nonatomic,readonly,nullable) UIView *photoView;
@property(nonatomic, readonly,copy) NSArray *feedViews;
-(UIView*) photoViewForFeed:(SSFeed) photoFeed;
@end
NS_ASSUME_NONNULL_END
Audited regions make default assumptions about some
pointers:
• Single-level pointers are assumed to be nonnull
• NSError** parameters are assumed to be nullable for both
levels
• Only annotate the nullable or null_unspecified cases
Nullability
Allow collections to be parameterized by element type:
“An array of views” ,
“A dictionary mapping strings to images”
• Improve expressivity of APIs
• Make collections easier to use
• Enable better static type checking
Lightweight Generics
Objective–C
@interface SNGFeedView
@property(nonatomic)NSArray <UIView*> feedSubviews;
@property(nonatomic,assign)BOOL filter;
@end
Swift
class SNGFeedView {
var subviews: [UIView] { get }
}
Lightweight Generics
• It tells compiler it’s object of some kind of of given type
extern __kindof NSApplication *NSApp; // NSApplication instance
NSObject *object = NSApp; // convert to super class
MyApplication *myApp = NSApp; // implicit downcast subclass
NSString *string = NSApp // Incorrect
• Much more useful than id, more type information in API
contract
• Allows messaging subclass methods
[NSApp praiseUser] // Invokes MyApplication method
KindOf Types
• Modernization of Objective-C
• Generating Bridging Headers
• Incremental Migration
eHarmony’s Plan to Tackle
Before you start:
• Create a Swift class for your corresponding Objective-C .m and .h
• Import relevant system frameworks
• Fill out an Objective-C bridging header if you need to access
Objective-C code from the same app target in your Swift file
• To make your Swift class accessible and usable back in Objective-
C, make it a descendant of an Objective-C class or mark it with the
@objc attribute
Migration
As you work:
• Set up your Swift class by subclassing Objective-C classes,
adopting Objective-C protocols, and more.
• See “Adopting Cocoa Design Patterns” for information on
translating common design patterns.
• To translate your properties from Objective-C to Swift, read
Properties in “The Swift Programming Language.”
• Declare simple macros as global constants, and translate
complex macros into functions.
Migration
After you finish:
• Update import statements in your Objective-C code (to #import
"ProductModuleName-Swift.h"), as described in “Importing Code
from Within the Same App Target”
• Remove the original Objective-C .m file from the target by
deselecting the target membership checkbox
• Update your code to use the Swift class name instead of the
Objective-C name if you gave the Swift class a different name
Migration
Questions?

More Related Content

What's hot

What's hot (20)

Angular 4 fronts
Angular 4 frontsAngular 4 fronts
Angular 4 fronts
 
Building a website with angular 2
Building a website with angular 2Building a website with angular 2
Building a website with angular 2
 
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
 
Angular crash course
Angular crash courseAngular crash course
Angular crash course
 
Introduction To Angular 4 - J2I
Introduction To Angular 4 - J2IIntroduction To Angular 4 - J2I
Introduction To Angular 4 - J2I
 
A Glimpse on Angular 4
A Glimpse on Angular 4A Glimpse on Angular 4
A Glimpse on Angular 4
 
Raml api designer
Raml   api designerRaml   api designer
Raml api designer
 
Introduction to angular 4
Introduction to angular 4Introduction to angular 4
Introduction to angular 4
 
Angular 4 Introduction Tutorial
Angular 4 Introduction TutorialAngular 4 Introduction Tutorial
Angular 4 Introduction Tutorial
 
Angular 6 - The Complete Guide
Angular 6 - The Complete GuideAngular 6 - The Complete Guide
Angular 6 - The Complete Guide
 
Angular 9
Angular 9 Angular 9
Angular 9
 
Angular tutorial
Angular tutorialAngular tutorial
Angular tutorial
 
Angular js
Angular jsAngular js
Angular js
 
Rupie asp.net
Rupie asp.netRupie asp.net
Rupie asp.net
 
Dive into Angular, part 4: Angular 2.0
Dive into Angular, part 4: Angular 2.0Dive into Angular, part 4: Angular 2.0
Dive into Angular, part 4: Angular 2.0
 
AngularJS Scopes
AngularJS ScopesAngularJS Scopes
AngularJS Scopes
 
White Paper : ASP.NET Core AngularJs 2 and Prime
White Paper : ASP.NET Core AngularJs 2 and PrimeWhite Paper : ASP.NET Core AngularJs 2 and Prime
White Paper : ASP.NET Core AngularJs 2 and Prime
 
Ng talk
Ng talkNg talk
Ng talk
 
Angular App Presentation
Angular App PresentationAngular App Presentation
Angular App Presentation
 
Anypoint platform
Anypoint platformAnypoint platform
Anypoint platform
 

Viewers also liked

Viewers also liked (8)

Swift LA Meetup at eHarmony- What's New in Swift 2.0
Swift LA Meetup at eHarmony- What's New in Swift 2.0Swift LA Meetup at eHarmony- What's New in Swift 2.0
Swift LA Meetup at eHarmony- What's New in Swift 2.0
 
Swift LA Meetup at eHarmony - What You Might Have Missed at WWDC 2015 with Ch...
Swift LA Meetup at eHarmony - What You Might Have Missed at WWDC 2015 with Ch...Swift LA Meetup at eHarmony - What You Might Have Missed at WWDC 2015 with Ch...
Swift LA Meetup at eHarmony - What You Might Have Missed at WWDC 2015 with Ch...
 
Letters from the Trenches: Lessons Learned Taking MongoDB to Production
Letters from the Trenches: Lessons Learned Taking MongoDB to ProductionLetters from the Trenches: Lessons Learned Taking MongoDB to Production
Letters from the Trenches: Lessons Learned Taking MongoDB to Production
 
In pursuit of messaging broker(s)
In pursuit of messaging broker(s)In pursuit of messaging broker(s)
In pursuit of messaging broker(s)
 
Data Science of Love
Data Science of LoveData Science of Love
Data Science of Love
 
Scalable Eventing Over Apache Mesos
Scalable Eventing Over Apache MesosScalable Eventing Over Apache Mesos
Scalable Eventing Over Apache Mesos
 
Middleware in Golang: InVision's Rye
Middleware in Golang: InVision's RyeMiddleware in Golang: InVision's Rye
Middleware in Golang: InVision's Rye
 
The monad fear
The monad fearThe monad fear
The monad fear
 

Similar to Swift LA Meetup at eHarmony- Swift and Enterprise and eHarmony with Heena Rastogi

4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
tilejak773
 

Similar to Swift LA Meetup at eHarmony- Swift and Enterprise and eHarmony with Heena Rastogi (20)

Mobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesMobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelines
 
Angular meetup 2 2019-08-29
Angular meetup 2   2019-08-29Angular meetup 2   2019-08-29
Angular meetup 2 2019-08-29
 
Introduction to angular | Concepts and Environment setup
Introduction to angular | Concepts and Environment setupIntroduction to angular | Concepts and Environment setup
Introduction to angular | Concepts and Environment setup
 
Facilitating Idiomatic Swift with Objective-C
Facilitating Idiomatic Swift with Objective-CFacilitating Idiomatic Swift with Objective-C
Facilitating Idiomatic Swift with Objective-C
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Asp.NETZERO - A Workshop Presentation by Citytech Software
Asp.NETZERO - A Workshop Presentation by Citytech SoftwareAsp.NETZERO - A Workshop Presentation by Citytech Software
Asp.NETZERO - A Workshop Presentation by Citytech Software
 
Swift programming language
Swift programming languageSwift programming language
Swift programming language
 
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
4 Anguadasdfasdasdfasdfsdfasdfaslar (1).pptx
 
ASP.NET vNext
ASP.NET vNextASP.NET vNext
ASP.NET vNext
 
Angular IO
Angular IOAngular IO
Angular IO
 
Pentesting iOS Apps - Runtime Analysis and Manipulation
Pentesting iOS Apps - Runtime Analysis and ManipulationPentesting iOS Apps - Runtime Analysis and Manipulation
Pentesting iOS Apps - Runtime Analysis and Manipulation
 
Angular from Zero to Mastery - Training (Intermediate)
Angular from Zero to Mastery - Training (Intermediate)Angular from Zero to Mastery - Training (Intermediate)
Angular from Zero to Mastery - Training (Intermediate)
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - Introduction
 
Developing modular Java applications
Developing modular Java applicationsDeveloping modular Java applications
Developing modular Java applications
 
Cloud compiler - Minor Project by students of CBPGEC
Cloud compiler - Minor Project by students of CBPGEC  Cloud compiler - Minor Project by students of CBPGEC
Cloud compiler - Minor Project by students of CBPGEC
 
2016 07 - CloudBridge Python library (XSEDE16)
2016 07 - CloudBridge Python library (XSEDE16)2016 07 - CloudBridge Python library (XSEDE16)
2016 07 - CloudBridge Python library (XSEDE16)
 
Announcing AWS CodeBuild - January 2017 Online Teck Talks
Announcing AWS CodeBuild - January 2017 Online Teck TalksAnnouncing AWS CodeBuild - January 2017 Online Teck Talks
Announcing AWS CodeBuild - January 2017 Online Teck Talks
 
Mvc4
Mvc4Mvc4
Mvc4
 

Recently uploaded

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 

Recently uploaded (20)

OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 

Swift LA Meetup at eHarmony- Swift and Enterprise and eHarmony with Heena Rastogi

  • 1. Swift & Enterprise & eHarmony • Why? • Bridging & Migration • eHarmony’s Plan to Tackle
  • 2. • Simpler to read • Type safety and hence code safety • Interacts with Objective-C Runtime seamlessly • Take advantage of Objective-C APIs and Cocoa design patterns • Open Source - we gain flexibility and freedom • Other platforms can also adopt Swift Why?
  • 3. 3 important aspects of Swift / Objective-C compatibility: • Interoperability Ability to interface between Swift and Objective-C in either direction • Mix and Match Allows you to create mixed-language apps containing both Swift and Objective-C files that can communicate with each other • Migration Migration from existing Objective-C code to Swift is made easy with interoperability and mix and match, making it possible to replace parts of your Objective-C apps with the latest Swift features Bridging & Migration
  • 4. 3 New features introduced for Objective-C : • Nullability for Objective-C • Lightweight Generics • Kind of Bridging & Migration
  • 5. Bridging & Migration Objective-C @interface SNGFeedView @property(nonatomic, readonly) UIView *photoView; @property(nonatomic, readonly, copy) NSArray *feedViews; - (UIView*) photoViewForFeed:(SSFeed) photoFeed; @end Swift class SNGFeedView { var photoView : UIView? var feedViews: [AnyObject]! func photoView(photoFeed:SSFeed) - > UIView }
  • 6. Indicate whether Objective-C/C pointers can be nil • Better communicate intent of APIs • Allows improved static checking • Improves usability of APIs in Swift Nullability
  • 7. Nullability Qualifiers Nullability Qualifier Usage Swift nullable Pointer may be nil UIView? nonnull nil is not a meaningful value UIView null_unspecified Neither nullable nor nonnull applies UIView! NOTE: Compiler does not change the way it generates code because of a non-null annotation.
  • 8. Example: NS_ASSUME_NONNULL_BEGIN @interface SNGFeedView @property(nonatomic,readonly,nullable) UIView *photoView; @property(nonatomic, readonly,copy) NSArray *feedViews; -(UIView*) photoViewForFeed:(SSFeed) photoFeed; @end NS_ASSUME_NONNULL_END Audited regions make default assumptions about some pointers: • Single-level pointers are assumed to be nonnull • NSError** parameters are assumed to be nullable for both levels • Only annotate the nullable or null_unspecified cases Nullability
  • 9. Allow collections to be parameterized by element type: “An array of views” , “A dictionary mapping strings to images” • Improve expressivity of APIs • Make collections easier to use • Enable better static type checking Lightweight Generics
  • 10. Objective–C @interface SNGFeedView @property(nonatomic)NSArray <UIView*> feedSubviews; @property(nonatomic,assign)BOOL filter; @end Swift class SNGFeedView { var subviews: [UIView] { get } } Lightweight Generics
  • 11. • It tells compiler it’s object of some kind of of given type extern __kindof NSApplication *NSApp; // NSApplication instance NSObject *object = NSApp; // convert to super class MyApplication *myApp = NSApp; // implicit downcast subclass NSString *string = NSApp // Incorrect • Much more useful than id, more type information in API contract • Allows messaging subclass methods [NSApp praiseUser] // Invokes MyApplication method KindOf Types
  • 12. • Modernization of Objective-C • Generating Bridging Headers • Incremental Migration eHarmony’s Plan to Tackle
  • 13. Before you start: • Create a Swift class for your corresponding Objective-C .m and .h • Import relevant system frameworks • Fill out an Objective-C bridging header if you need to access Objective-C code from the same app target in your Swift file • To make your Swift class accessible and usable back in Objective- C, make it a descendant of an Objective-C class or mark it with the @objc attribute Migration
  • 14. As you work: • Set up your Swift class by subclassing Objective-C classes, adopting Objective-C protocols, and more. • See “Adopting Cocoa Design Patterns” for information on translating common design patterns. • To translate your properties from Objective-C to Swift, read Properties in “The Swift Programming Language.” • Declare simple macros as global constants, and translate complex macros into functions. Migration
  • 15. After you finish: • Update import statements in your Objective-C code (to #import "ProductModuleName-Swift.h"), as described in “Importing Code from Within the Same App Target” • Remove the original Objective-C .m file from the target by deselecting the target membership checkbox • Update your code to use the Swift class name instead of the Objective-C name if you gave the Swift class a different name Migration