SlideShare a Scribd company logo
Swiftly Switching:
The Transition from Obj-C to Swift
Big Design Dallas 2015 | @MaeganSnee
WHO AM I?
@MaeganSnee
HARDWARE / SOFTWARE
@MaeganSnee
QUESTIONS
@MaeganSnee
Objective-C is the primary programming
language you use when writing software for
OS X and iOS. It’s a superset of the C
programming language and provides object-
oriented capabilities and a dynamic runtime.
Swift is a powerful and intuitive programming
language for iOS, OS X, and watchOS. Writing
Swift code is interactive and fun, the syntax is
concise yet expressive, and apps run lightning-
fast. Swift is ready for your next project — or
addition into your current app — because Swift
code works side-by-side with Objective-C. 
@MaeganSnee
developer.apple.com
DIFFERENCES
@MaeganSnee
HEADER FILES
@MaeganSnee
Objective-C
 Swift
@interface ViewController : UIViewController!
!
@property (strong, nonatomic) IBOutlet UITextField *textField;!
@property (strong, nonatomic) IBOutlet UIImageView *imageView;!
!
@end!
HEADER FILES
Objective-C
@MaeganSnee
Swift
class ViewController: UIViewController {!
!
@IBOutlet var imageView: UIImageView!!
@IBOutlet var textField: UITextField!!
!
}!
BRACKETS & SEMICOLONS
Objective-C
@MaeganSnee
UIView *subView = [[UIView alloc] !
initWithFrame:CGRectMake(50, 50, 100, 100)];!
subView.backgroundColor = [UIColor redColor];!
[[self view] addSubview:subView];!
Swift
let subView:UIView = UIView.init(frame: !
CGRectMake(50, 50, 100, 100))!
subView.backgroundColor = UIColor.redColor()!
self.view.addSubview(subView)!
AMOUNT OF CODE
Objective-C
@MaeganSnee
@property (strong, nonatomic) IBOutlet UITextField *input;!
@property (strong, nonatomic) IBOutlet UILabel *label;!
!
[self.label setText:[NSString stringWithFormat:@"Welcome, !
%@!", self.input.text]];!
Swift
@IBOutlet var input: UITextField!!
@IBOutlet var label: UILabel!!
!
label.text = "Welcome, (input.text)!"!
EASE OF USE
Objective-C
@MaeganSnee
// defining a method!
- (void)changeImage:(int)num { ... }!
!
// calling the method!
[self changeImage:number];!
!
Swift
// defining a method!
func changeImage(num:Int) { ... }!
!
// calling the method!
changeImage(number)!
LIKES
@MaeganSnee
SHORTER SYNTAX
Objective-C
@MaeganSnee
@property (strong, nonatomic) IBOutlet UITextField *input;!
@property (strong, nonatomic) IBOutlet UILabel *label;!
!
[self.label setText:[NSString stringWithFormat:@"Welcome, !
%@!", self.input.text]];!
Swift
@IBOutlet var input: UITextField!!
@IBOutlet var label: UILabel!!
!
label.text = "Welcome, (input.text)!"!
CLEANER CLASSES
Objective-C
@MaeganSnee
#import "ViewController.h”!
!
@implementation ViewController!
// methods!
@end!
Swift
class ViewController: UIViewController {!
// properties and methods!
}!
STRING INTERPOLATION
Objective-C
@MaeganSnee
int age = 3;!
NSString *name = "Tardar Sauce";!
NSString *funFact = [NSString stringWithFormat:@"Grumpy!
Cat’s real name is %@ and she is %d !
years old.", name, age];!
Swift
let age:Int = 3!
let name:String = "Tardar Sauce"!
let funFact:String = "Grumpy Cat’s real name is (name) !
and she is (age) years old"!
SIMPLE DEFINITIONS (ARRAY)
Objective-C
@MaeganSnee
NSMutableArray *emptyArray = [[NSMutableArray alloc]init];!
!
NSArray *array = [NSArray arrayWithObjects: @"kids", !
@"wife", @"husband", nil];!
Swift
var emptyArray = [String]()!
!
let array = ["kids", "wife", "husband"]!
ITERATIONS (ARRAY)
Objective-C
@MaeganSnee
for (NSString *value in array) {!
NSLog(@"Hide yo’ %@.", value);!
}!
!
!
!
Swift
for value in array {!
print("Hide yo’ (value).”)!
}!
SIMPLE DEFINITIONS (DICTIONARY)
Objective-C
@MaeganSnee
NSMutableDictionary *emptyDictionary = !
[[NSMutableDictionary alloc] init];!
!
NSDictionary *dictionary= @{!
@"first" : @"Leeroy",!
@"last" : @"Jenkins"!
};!
Swift
var emptyDictionary = Dictionary()!
!
var dictionary = [!
"first" : "Leeroy",!
"last" : "Jenkins"!
]!
ITERATIONS (DICTIONARY)
Objective-C
@MaeganSnee
for (id key in dictionary) {!
NSLog(@"Player’s %@ name is %@.", key, !
dictionary[key]);!
}!
!
Swift
for (key, value) in dictionary {!
print("Player’s (key) name is (value).")!
}!
DISLIKES
(SORT OF)
@MaeganSnee
VARIABLES VS. CONSTANTS
Variable
@MaeganSnee
var language = "Objective-C"!
language = "Swift"!
// language is now Swift!
Constant
let language = "Objective-C”!
language = "Swift"!
// compile-time error; language cannot be changed!
!
var language2 = "Swift"!
// compile-time warning; “consider changing to let”!
TYPE INFERENCE
Typed
@MaeganSnee
let number:Int = 42!
let phrase:String = "meaning of life"!
let decimal:Double = 3.14!
!
Inferred
let number = 42 // Int!
let phrase = "meaning of life" // String!
let decimal = 3.14 // Double!
OPTIONALS
Optionals
@MaeganSnee
var name:String! = "Lone Wanderer" // optional String!
!
var newName:String? // empty optional String!
newName = "Sole Survivor" // String no longer nil!
!
!
nil
var westVault:Int? // initially contains no value!
westVault = 101 // now has value of 101!
var eastVault:Int? = 111 // initially has value of 111!
eastVault = nil // now contains no value!
UNWRAPPING OPTIONALS
Unwrapping
@MaeganSnee
if newName != nil {!
print("His name is (newName!)")!
}!
Binding
if let vaultNumber = westVault {!
print("Vault (vaultNumber) is home to (name)")!
} else {!
print("Vault could not be located")!
}!
PLAYGROUND
@MaeganSnee
AUTOLAYOUT
@MaeganSnee
EXAMPLES
@MaeganSnee
THANK YOU
@MaeganSnee
slideshare.net/MaeganSnee
github.com/sneem

More Related Content

PDF
Autolayout
PPTX
c programme
PDF
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
PDF
Objective-C for Java Developers, Lesson 1
PPT
The smartpath information systems c pro
PDF
To Swift 2...and Beyond!
PPTX
Swift vs Objective-C
PDF
Intro toswift1
Autolayout
c programme
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Objective-C for Java Developers, Lesson 1
The smartpath information systems c pro
To Swift 2...and Beyond!
Swift vs Objective-C
Intro toswift1

Similar to Swiftly Switching: The Transition from Obj-C to Swift (20)

PDF
Swift for-rubyists
PDF
Introduction to Swift programming language.
PDF
Swift, swiftly
PPT
Swift Basics with iOS 8 features
PDF
iOS NSAgora #3: Objective-C vs. Swift
PDF
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
PPTX
IOS Swift language 2nd tutorial
PDF
The Swift Programming Language with iOS App
PDF
Swift, a quick overview
PDF
Irving iOS Jumpstart Meetup - Objective-C Session 2
PDF
Swift Basics
PDF
Swift - the future of iOS app development
PPTX
Introduction to Swift (tutorial)
PDF
iOS for Android Developers (with Swift)
PDF
Quick swift tour
PDF
Introduction_Swift
PDF
Swift Tutorial Part 2. The complete guide for Swift programming language
PDF
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
PDF
Custom view
Swift for-rubyists
Introduction to Swift programming language.
Swift, swiftly
Swift Basics with iOS 8 features
iOS NSAgora #3: Objective-C vs. Swift
iOS Bootcamp: learning to create awesome apps on iOS using Swift (Lecture 02)
IOS Swift language 2nd tutorial
The Swift Programming Language with iOS App
Swift, a quick overview
Irving iOS Jumpstart Meetup - Objective-C Session 2
Swift Basics
Swift - the future of iOS app development
Introduction to Swift (tutorial)
iOS for Android Developers (with Swift)
Quick swift tour
Introduction_Swift
Swift Tutorial Part 2. The complete guide for Swift programming language
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
Custom view
Ad

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
cuic standard and advanced reporting.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Approach and Philosophy of On baking technology
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Big Data Technologies - Introduction.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
cuic standard and advanced reporting.pdf
The AUB Centre for AI in Media Proposal.docx
20250228 LYD VKU AI Blended-Learning.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Approach and Philosophy of On baking technology
The Rise and Fall of 3GPP – Time for a Sabbatical?
MYSQL Presentation for SQL database connectivity
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
MIND Revenue Release Quarter 2 2025 Press Release
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Spectroscopy.pptx food analysis technology
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Understanding_Digital_Forensics_Presentation.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Big Data Technologies - Introduction.pptx
Ad

Swiftly Switching: The Transition from Obj-C to Swift