SlideShare une entreprise Scribd logo
1  sur  51
Swift LA
22 June 2015
eHarmony
• Introduction
• What You Might Have Missed at WWDC
• Swift 2.0
• Swift & Enterprise & eHarmony
• Questions?
Agenda
“We came together in 2000 believing that with a mix of
psychology and some cutting edge technology, we could create
relationships that were happier, more fulfilling and enduring.
With over 61 million registered users, we’ve successfully
married more than 565,000 couples, and are responsible for
nearly 5% of marriages in the US — that’s 438 people every
day that say ‘I Do’ because of eHarmony.”
“Millions of people have used eHarmony’s Compatibility
Matching System to find compatible long-term relationships.
Today, an average of 438 eHarmony members marry every
day in the United States as a result of being matched on the
site.”
Who is eHarmony?
Currently, we maintain Desktop Web, Mobile Web, iOS
and Android apps for our scientific matching service.
Our iOS App currently boasts:
• 8 billion downloads
• Best selling app
• Biggest grossing app
The team has been busy!
The eHarmony App
• Dr. Gary Philipp – Sr. Manager, Mobile Engineering
Gary has a PhD in Engineering and a Masters in Behavioral Science. He is the old man of the
group (programming Apple products for over 30 years) and his first computer was an Apple II.
• Chris Truman – iOS Engineer
Self taught iOS developer, born and raised in LA. Previously worked at Urbanspoon and
TripAdvisor. Currently mentoring students in Swift through the Thinkful & One Month Swift programs. Loves
Dogs, Comic Books, and long walks on the beach.
• Premal Mistry – iOS Engineer
Premal loves designing and developing apps for iOS and Android and has over 6 years of
experience in Software Development. He has a Masters in Computer Science and is passionate about
learning new technologies (Swift, Design Patterns, Animation, etc). During weekends, I love to watch
movies, TV shows, hanging out with friends and Yelping various food places in LA.
• Heena Rastogi – Senior iOS Engineer
Heena earned a Masters in Computer Science (Multimedia and Creative Technologies) and
has been developing iOS apps for the past 6 years. She loves being a part of development projects that
are focused on creative and exciting technologies. Outside of coding, she enjoys reading, running on the
beach and listening to electronic music.
The Team
• UIStackView
• Rich Playgrounds
• Slide Over & Split View & PiP Video
• Universal Links
• App Search & CoreSpotlight
• SFSafariViewController
• App Transport Security
• App Thinning
• Storyboard References
• UI Testing
• Metal & Games
• TestFlight and Push Notifications
What You Might Have Missed at
WWDC 2015
• Axis
• Distribution
• Spacing
• Animatable
UIStackView
• Markdown
• Multi-Pages
• Embedded Resources
Rich Playgrounds
• Launch Screen Storyboard
• Autolayout & Size Classes
• Window vs Screen
Slide Over & Split View & PiP
• App Site Association
• Similar to Android Default Intents
Universal Links
• Background Indexing
• NSUserActivity
• Web Markup
• Meta Data
App Search & CoreSpotlight
• Separate process
• Cookies & Keychain
• Tint Color
• Custom Activity Items
SFSafariViewController
• HTTPS is mandatory-ish
• Info.plist disabling
• Exception Domains
App Transport Security
• Asset Splitting - @1x, @2x, @3x
• On Demand Resources
• BitCode
App Thinning
• Split up Large Storyboards
• Custom Unwind Segues
Storyboard References
• New Testing Bundle Type
• Record a Script
UI Testing
• Core Animation
• On the Mac
• ReplayKit, GameplayKit, ModelKit
Metal & Games
• Tester Limit increased to 2000
• Push Notifications Text Input
• 4k Push Payload Limit Increase
• Feedback Service will be deprecated in 2016
TestFlight & Push Notifications
• Checking API Availability
• Synthesized Headers
• Protocol Extension
• Error Handling
• And more…
What’s New in Swift 2.0
Apple always rolls out new API’s and classes
throughout the year.
How do we check for API & Class availability?
Checking API Availability in Swift
The old way:
if NSClassFromString("SFSafariViewControler") != nil {
let eHAdviceVC = SFSafariViewController(URL: url, entersReaderIfAvailable: true)
eHAdviceVC.delegate = self
presentViewController(eHAdviceVC, animated: true, completion: nil)
} else {
let eHAdviceVC = eHAdviceViewController(URL: url);
presentViewController(eHAdviceVC, animated: true, completion: nil)
}
Checking API Availability in Swift
Checking API Availability in Swift
The new way:
if #available(iOS 9, OS X 10.10, watchOS 2, *) {
let eHAdviceVC = SFSafariViewController(URL: url, entersReaderIfAvailable: true)
eHAdviceVC.delegate = self
presentViewController(eHAdviceVC, animated: true, completion: nil)
} else {
let eHAdviceVC = eHAdviceViewController();
presentViewController(eHAdviceVC, animated: true, completion: nil)
}
Synthesized header files:
Xcode 7 scans through your code and produces virtual header files
that summarize the exposed methods with none of the code
Documentation - Similar to Apple's own classes
How to generate synthesized headers in Xcode 7?
Xcode 7, go to Navigate > Generated Interface.
Synthesized Headers
Synthesized Headers
extension NSURLRequest: URLRequestConvertible {
public var URLRequest: NSURLRequest
}
func URLRequest(method: Method, URL: URLStringConvertible) -> NSURLRequest
/**
Creates a request using the shared manager instance for the specified method, URL string, parameters, and parameter
encoding.
:param: method The HTTP method.
:param: URLString The URL string.
:param: parameters The parameters. `nil` by default.
:param: encoding The parameter encoding. `.URL` by default.
:returns: The created request.
*/
public func request(method: Method, URLString: URLStringConvertible, parameters: [String: AnyObject]? = nil, encoding:
ParameterEncoding = .URL) -> Request
/**
Creates a request using the shared manager instance for the specified URL request.
If `startRequestsImmediately` is `true`, the request will have `resume()` called before being returned.
:param: URLRequest The URL request
:returns: The created request.
*
Protocol Extensions
Protocols can be extended to provide method
and property implementations to conforming
types.
You can use protocol extensions to provide a
default implementation to any method or property
requirement of that protocol.
Protocol Extensions
Example:
let ageOfEmployees: [Int?] = [30, 32, nil, 45, 50, 12, 8, 25, nil]
extension SequenceType where Generator.Element: OptionalType {
var purify: [Self.Generator.Element.T] {
return self.map { $0.optional }.filter { $0 != nil }.map { $0! }
}
}
let ageOfEmployees: [Int?] = [30, 32, nil, 45, 50, 12, 8, 25, nil]
ageOfEmployees.purify
[30, 32, 45, 50, 12, 8, 25]
Error Handling
Example:
func refreshActivityFeed() {
let refreshToken = login()
loadActivityFeed(refreshToken)
updateUI()
}
Error Handling
The Old Way:
func refreshActivityFeed() {
let refreshToken:String? = login(username, error:&error)
if (error != nil) {
if let error = error {
switch (error.code) {
case ERROR_UNAUTHORIZED:
showLoginVC()
case ERROR_FORBIDDEN:
showErrorAlert()
case ERROR_NOT_FOUND:
showLoginVC()
default:
showErrorAlert()
}
}
} else {
// Fetch the most recent activity feeds from the server
// Parse and prepare data structure
// Update UI
loadActivityFeed(refreshToken!)
updateUI()
}
}
The New Way:
func refreshActivityFeed() {
do
{
let refreshToken = try login(username)
loadActivityFeed(refreshToken)
updateUI()
} catch (LoginError.ERROR_UNAUTHORIZED) {
showLoginVC()
} catch (LoginError.ERROR_FORBIDDEN) {
showErrorAlert()
} catch (LoginError.ERROR_NOT_FOUND) {
showLoginVC()
} catch {
showErrorAlert()
}
}
Error Handling
Error Handling
Representing Errors
• ErrorType is a protocol in the Swift Standard Library
• Any type that conforms to ErrorType can be thrown and caught
• Can make your own types conform as well
• enum is great for groups of related errors
enum LoginError : ErrorType {
case ERROR_UNAUTHORIZED
case ERROR_FORBIDDEN
case ERROR_NOT_FOUND
case ERROR_NOT_ALLOWED
case ErrorWithMessage(code: Int, message: String)
}
Throwing Errors:
enum VendingMachineError: ErrorType {
case InvalidSelection
case InsufficientFunds(required: Double)
case OutOfStock
}
func purchaseItemFromVendingMachine(item: VendingItem) throws -> Bool {
if item.count() > 0 {
// .....
return true
} else {
throw VendingMachineError.OutOfStock
}
}
Error Handling
Catching and Handling Errors:
func refreshActivityFeed() {
do
{
let refreshToken = try loginWithUserName(username)
loadActivityFeed(refreshToken)
updateUI()
} catch (LoginError.ERROR_UNAUTHORIZED) {
showLoginVC()
} catch (LoginError.ERROR_FORBIDDEN) {
showErrorAlert()
} catch (LoginError.ERROR_NOT_FOUND) {
showLoginVC()
} catch {
showErrorAlert()
}
}
Error Handling
Disabling Error Propagation:
try! loadConfiguration()
Error Handling
Specifying Cleanup Actions:
func processFile(filename: String) throws {
if exists(filename) {
do {
let file = try open(filename)
defer {
close(file)
}
while let line = try file.readline() {
...
}
} catch {
...
}
}
}
Error Handling
And More…
Guard:
func validateJSON() -> Bool {
guard let name = person["name"] else {
return false
}
.....
.....
return true
}
• Designed to solve pyramid of doom problem
• Extremely useful for early exit
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?

Contenu connexe

Tendances

Tendances (15)

Angularjs
AngularjsAngularjs
Angularjs
 
Prairie DevCon 2015 - Crafting Evolvable API Responses
Prairie DevCon 2015 - Crafting Evolvable API ResponsesPrairie DevCon 2015 - Crafting Evolvable API Responses
Prairie DevCon 2015 - Crafting Evolvable API Responses
 
A tech writer, a map, and an app
A tech writer, a map, and an appA tech writer, a map, and an app
A tech writer, a map, and an app
 
Understanding Identity in the World of Web APIs – Ronnie Mitra, API Architec...
Understanding Identity in the World of Web APIs – Ronnie Mitra,  API Architec...Understanding Identity in the World of Web APIs – Ronnie Mitra,  API Architec...
Understanding Identity in the World of Web APIs – Ronnie Mitra, API Architec...
 
Effectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby ConfEffectively Testing Services - Burlington Ruby Conf
Effectively Testing Services - Burlington Ruby Conf
 
Scaling your Android App With Modularization
Scaling your Android App With ModularizationScaling your Android App With Modularization
Scaling your Android App With Modularization
 
CiviCRM API v3
CiviCRM API v3CiviCRM API v3
CiviCRM API v3
 
GraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learnedGraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learned
 
Beyond MVC: from Model to Domain
Beyond MVC: from Model to DomainBeyond MVC: from Model to Domain
Beyond MVC: from Model to Domain
 
Extreme APIs for a better tomorrow
Extreme APIs for a better tomorrowExtreme APIs for a better tomorrow
Extreme APIs for a better tomorrow
 
Crafting Quality PHP Applications (PHPkonf 2018)
Crafting Quality PHP Applications (PHPkonf 2018)Crafting Quality PHP Applications (PHPkonf 2018)
Crafting Quality PHP Applications (PHPkonf 2018)
 
BruJUG Brussels GraphQL when RESR API is to less - lessons learned
BruJUG Brussels GraphQL when RESR API is to less - lessons learnedBruJUG Brussels GraphQL when RESR API is to less - lessons learned
BruJUG Brussels GraphQL when RESR API is to less - lessons learned
 
GraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learnedGraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learned
 
Cross Platform Mobile Apps with the Ionic Framework
Cross Platform Mobile Apps with the Ionic FrameworkCross Platform Mobile Apps with the Ionic Framework
Cross Platform Mobile Apps with the Ionic Framework
 
Testing with Ruby
Testing with RubyTesting with Ruby
Testing with Ruby
 

Similaire à Swift meetup22june2015

OpenSocial Intro
OpenSocial IntroOpenSocial Intro
OpenSocial Intro
Pamela Fox
 
The liferay case: lessons learned evolving from RPC to Hypermedia REST APIs
The liferay case: lessons learned evolving from RPC to Hypermedia REST APIsThe liferay case: lessons learned evolving from RPC to Hypermedia REST APIs
The liferay case: lessons learned evolving from RPC to Hypermedia REST APIs
Jorge Ferrer
 
BarCamp KL H20 Open Social Hackathon
BarCamp KL H20 Open Social HackathonBarCamp KL H20 Open Social Hackathon
BarCamp KL H20 Open Social Hackathon
marvin337
 

Similaire à Swift meetup22june2015 (20)

Open Social Presentation - GSP West 2008
Open Social Presentation - GSP West 2008Open Social Presentation - GSP West 2008
Open Social Presentation - GSP West 2008
 
Codeigniter
CodeigniterCodeigniter
Codeigniter
 
Get started with building native mobile apps interacting with SharePoint
Get started with building native mobile apps interacting with SharePointGet started with building native mobile apps interacting with SharePoint
Get started with building native mobile apps interacting with SharePoint
 
I Love APIs Europe 2015: Developer Sessions
I Love APIs Europe 2015: Developer SessionsI Love APIs Europe 2015: Developer Sessions
I Love APIs Europe 2015: Developer Sessions
 
API Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIsAPI Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIs
 
OpenSocial Intro
OpenSocial IntroOpenSocial Intro
OpenSocial Intro
 
Are API Services Taking Over All the Interesting Data Science Problems?
Are API Services Taking Over All the Interesting Data Science Problems?Are API Services Taking Over All the Interesting Data Science Problems?
Are API Services Taking Over All the Interesting Data Science Problems?
 
APIs for the Internet of Things
APIs for the Internet of ThingsAPIs for the Internet of Things
APIs for the Internet of Things
 
Intro To Spring Python
Intro To Spring PythonIntro To Spring Python
Intro To Spring Python
 
The liferay case: lessons learned evolving from RPC to Hypermedia REST APIs
The liferay case: lessons learned evolving from RPC to Hypermedia REST APIsThe liferay case: lessons learned evolving from RPC to Hypermedia REST APIs
The liferay case: lessons learned evolving from RPC to Hypermedia REST APIs
 
API Product Opportunity Responsibility Nicolas Sierro 2015.pptx
API Product Opportunity Responsibility Nicolas Sierro 2015.pptxAPI Product Opportunity Responsibility Nicolas Sierro 2015.pptx
API Product Opportunity Responsibility Nicolas Sierro 2015.pptx
 
Playing with parse.com
Playing with parse.comPlaying with parse.com
Playing with parse.com
 
I Love APIs - Oct 2015
I Love APIs - Oct 2015I Love APIs - Oct 2015
I Love APIs - Oct 2015
 
BarCamp KL H20 Open Social Hackathon
BarCamp KL H20 Open Social HackathonBarCamp KL H20 Open Social Hackathon
BarCamp KL H20 Open Social Hackathon
 
Mobile Devices and SharePoint - Sahil Malik
Mobile Devices and SharePoint - Sahil MalikMobile Devices and SharePoint - Sahil Malik
Mobile Devices and SharePoint - Sahil Malik
 
Mobile devices and SharePoint
Mobile devices and SharePointMobile devices and SharePoint
Mobile devices and SharePoint
 
Office add ins community call - april 2019
Office add ins community call - april 2019Office add ins community call - april 2019
Office add ins community call - april 2019
 
How to Design and Build a Great Web API
How to Design and Build a Great Web APIHow to Design and Build a Great Web API
How to Design and Build a Great Web API
 
Survival Strategies for API Documentation: Presentation to Southwestern Ontar...
Survival Strategies for API Documentation: Presentation to Southwestern Ontar...Survival Strategies for API Documentation: Presentation to Southwestern Ontar...
Survival Strategies for API Documentation: Presentation to Southwestern Ontar...
 
Telerik AppBuilder Presentation for TelerikNEXT Conference
Telerik AppBuilder Presentation for TelerikNEXT ConferenceTelerik AppBuilder Presentation for TelerikNEXT Conference
Telerik AppBuilder Presentation for TelerikNEXT Conference
 

Dernier

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
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
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 

Dernier (20)

%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%+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...
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
%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
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
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...
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 

Swift meetup22june2015

  • 1. Swift LA 22 June 2015 eHarmony
  • 2. • Introduction • What You Might Have Missed at WWDC • Swift 2.0 • Swift & Enterprise & eHarmony • Questions? Agenda
  • 3. “We came together in 2000 believing that with a mix of psychology and some cutting edge technology, we could create relationships that were happier, more fulfilling and enduring. With over 61 million registered users, we’ve successfully married more than 565,000 couples, and are responsible for nearly 5% of marriages in the US — that’s 438 people every day that say ‘I Do’ because of eHarmony.” “Millions of people have used eHarmony’s Compatibility Matching System to find compatible long-term relationships. Today, an average of 438 eHarmony members marry every day in the United States as a result of being matched on the site.” Who is eHarmony?
  • 4. Currently, we maintain Desktop Web, Mobile Web, iOS and Android apps for our scientific matching service. Our iOS App currently boasts: • 8 billion downloads • Best selling app • Biggest grossing app The team has been busy! The eHarmony App
  • 5. • Dr. Gary Philipp – Sr. Manager, Mobile Engineering Gary has a PhD in Engineering and a Masters in Behavioral Science. He is the old man of the group (programming Apple products for over 30 years) and his first computer was an Apple II. • Chris Truman – iOS Engineer Self taught iOS developer, born and raised in LA. Previously worked at Urbanspoon and TripAdvisor. Currently mentoring students in Swift through the Thinkful & One Month Swift programs. Loves Dogs, Comic Books, and long walks on the beach. • Premal Mistry – iOS Engineer Premal loves designing and developing apps for iOS and Android and has over 6 years of experience in Software Development. He has a Masters in Computer Science and is passionate about learning new technologies (Swift, Design Patterns, Animation, etc). During weekends, I love to watch movies, TV shows, hanging out with friends and Yelping various food places in LA. • Heena Rastogi – Senior iOS Engineer Heena earned a Masters in Computer Science (Multimedia and Creative Technologies) and has been developing iOS apps for the past 6 years. She loves being a part of development projects that are focused on creative and exciting technologies. Outside of coding, she enjoys reading, running on the beach and listening to electronic music. The Team
  • 6. • UIStackView • Rich Playgrounds • Slide Over & Split View & PiP Video • Universal Links • App Search & CoreSpotlight • SFSafariViewController • App Transport Security • App Thinning • Storyboard References • UI Testing • Metal & Games • TestFlight and Push Notifications What You Might Have Missed at WWDC 2015
  • 7. • Axis • Distribution • Spacing • Animatable UIStackView
  • 8. • Markdown • Multi-Pages • Embedded Resources Rich Playgrounds
  • 9. • Launch Screen Storyboard • Autolayout & Size Classes • Window vs Screen Slide Over & Split View & PiP
  • 10. • App Site Association • Similar to Android Default Intents Universal Links
  • 11. • Background Indexing • NSUserActivity • Web Markup • Meta Data App Search & CoreSpotlight
  • 12. • Separate process • Cookies & Keychain • Tint Color • Custom Activity Items SFSafariViewController
  • 13. • HTTPS is mandatory-ish • Info.plist disabling • Exception Domains App Transport Security
  • 14. • Asset Splitting - @1x, @2x, @3x • On Demand Resources • BitCode App Thinning
  • 15. • Split up Large Storyboards • Custom Unwind Segues Storyboard References
  • 16. • New Testing Bundle Type • Record a Script UI Testing
  • 17. • Core Animation • On the Mac • ReplayKit, GameplayKit, ModelKit Metal & Games
  • 18. • Tester Limit increased to 2000 • Push Notifications Text Input • 4k Push Payload Limit Increase • Feedback Service will be deprecated in 2016 TestFlight & Push Notifications
  • 19. • Checking API Availability • Synthesized Headers • Protocol Extension • Error Handling • And more… What’s New in Swift 2.0
  • 20. Apple always rolls out new API’s and classes throughout the year. How do we check for API & Class availability? Checking API Availability in Swift
  • 21. The old way: if NSClassFromString("SFSafariViewControler") != nil { let eHAdviceVC = SFSafariViewController(URL: url, entersReaderIfAvailable: true) eHAdviceVC.delegate = self presentViewController(eHAdviceVC, animated: true, completion: nil) } else { let eHAdviceVC = eHAdviceViewController(URL: url); presentViewController(eHAdviceVC, animated: true, completion: nil) } Checking API Availability in Swift
  • 22. Checking API Availability in Swift The new way: if #available(iOS 9, OS X 10.10, watchOS 2, *) { let eHAdviceVC = SFSafariViewController(URL: url, entersReaderIfAvailable: true) eHAdviceVC.delegate = self presentViewController(eHAdviceVC, animated: true, completion: nil) } else { let eHAdviceVC = eHAdviceViewController(); presentViewController(eHAdviceVC, animated: true, completion: nil) }
  • 23. Synthesized header files: Xcode 7 scans through your code and produces virtual header files that summarize the exposed methods with none of the code Documentation - Similar to Apple's own classes How to generate synthesized headers in Xcode 7? Xcode 7, go to Navigate > Generated Interface. Synthesized Headers
  • 24. Synthesized Headers extension NSURLRequest: URLRequestConvertible { public var URLRequest: NSURLRequest } func URLRequest(method: Method, URL: URLStringConvertible) -> NSURLRequest /** Creates a request using the shared manager instance for the specified method, URL string, parameters, and parameter encoding. :param: method The HTTP method. :param: URLString The URL string. :param: parameters The parameters. `nil` by default. :param: encoding The parameter encoding. `.URL` by default. :returns: The created request. */ public func request(method: Method, URLString: URLStringConvertible, parameters: [String: AnyObject]? = nil, encoding: ParameterEncoding = .URL) -> Request /** Creates a request using the shared manager instance for the specified URL request. If `startRequestsImmediately` is `true`, the request will have `resume()` called before being returned. :param: URLRequest The URL request :returns: The created request. *
  • 25. Protocol Extensions Protocols can be extended to provide method and property implementations to conforming types. You can use protocol extensions to provide a default implementation to any method or property requirement of that protocol.
  • 26. Protocol Extensions Example: let ageOfEmployees: [Int?] = [30, 32, nil, 45, 50, 12, 8, 25, nil] extension SequenceType where Generator.Element: OptionalType { var purify: [Self.Generator.Element.T] { return self.map { $0.optional }.filter { $0 != nil }.map { $0! } } } let ageOfEmployees: [Int?] = [30, 32, nil, 45, 50, 12, 8, 25, nil] ageOfEmployees.purify [30, 32, 45, 50, 12, 8, 25]
  • 27. Error Handling Example: func refreshActivityFeed() { let refreshToken = login() loadActivityFeed(refreshToken) updateUI() }
  • 28. Error Handling The Old Way: func refreshActivityFeed() { let refreshToken:String? = login(username, error:&error) if (error != nil) { if let error = error { switch (error.code) { case ERROR_UNAUTHORIZED: showLoginVC() case ERROR_FORBIDDEN: showErrorAlert() case ERROR_NOT_FOUND: showLoginVC() default: showErrorAlert() } } } else { // Fetch the most recent activity feeds from the server // Parse and prepare data structure // Update UI loadActivityFeed(refreshToken!) updateUI() } }
  • 29. The New Way: func refreshActivityFeed() { do { let refreshToken = try login(username) loadActivityFeed(refreshToken) updateUI() } catch (LoginError.ERROR_UNAUTHORIZED) { showLoginVC() } catch (LoginError.ERROR_FORBIDDEN) { showErrorAlert() } catch (LoginError.ERROR_NOT_FOUND) { showLoginVC() } catch { showErrorAlert() } } Error Handling
  • 30. Error Handling Representing Errors • ErrorType is a protocol in the Swift Standard Library • Any type that conforms to ErrorType can be thrown and caught • Can make your own types conform as well • enum is great for groups of related errors enum LoginError : ErrorType { case ERROR_UNAUTHORIZED case ERROR_FORBIDDEN case ERROR_NOT_FOUND case ERROR_NOT_ALLOWED case ErrorWithMessage(code: Int, message: String) }
  • 31. Throwing Errors: enum VendingMachineError: ErrorType { case InvalidSelection case InsufficientFunds(required: Double) case OutOfStock } func purchaseItemFromVendingMachine(item: VendingItem) throws -> Bool { if item.count() > 0 { // ..... return true } else { throw VendingMachineError.OutOfStock } } Error Handling
  • 32. Catching and Handling Errors: func refreshActivityFeed() { do { let refreshToken = try loginWithUserName(username) loadActivityFeed(refreshToken) updateUI() } catch (LoginError.ERROR_UNAUTHORIZED) { showLoginVC() } catch (LoginError.ERROR_FORBIDDEN) { showErrorAlert() } catch (LoginError.ERROR_NOT_FOUND) { showLoginVC() } catch { showErrorAlert() } } Error Handling
  • 33. Disabling Error Propagation: try! loadConfiguration() Error Handling
  • 34. Specifying Cleanup Actions: func processFile(filename: String) throws { if exists(filename) { do { let file = try open(filename) defer { close(file) } while let line = try file.readline() { ... } } catch { ... } } } Error Handling
  • 35. And More… Guard: func validateJSON() -> Bool { guard let name = person["name"] else { return false } ..... ..... return true } • Designed to solve pyramid of doom problem • Extremely useful for early exit
  • 36. Swift & Enterprise & eHarmony • Why? • Bridging & Migration • eHarmony’s Plan to Tackle
  • 37. • 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?
  • 38. 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
  • 39. 3 New features introduced for Objective-C : • Nullability for Objective-C • Lightweight Generics • Kind of Bridging & Migration
  • 40. 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 }
  • 41. 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
  • 42. 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.
  • 43. 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
  • 44. 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
  • 45. Objective–C @interface SNGFeedView @property(nonatomic)NSArray <UIView*> feedSubviews; @property(nonatomic,assign)BOOL filter; @end Swift class SNGFeedView { var subviews: [UIView] { get } } Lightweight Generics
  • 46. • 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
  • 47. • Modernization of Objective-C • Generating Bridging Headers • Incremental Migration eHarmony’s Plan to Tackle
  • 48. 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
  • 49. 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
  • 50. 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