SlideShare a Scribd company logo
1 of 37
Download to read offline
Text
Swift Programming for iOS
A Modern Alternative to Objective-C
What is Swift?
Swift is a new programming language created by Apple as the
language of their future. Swift was originally announced during
the Apple Worldwide Developer Conference in June of 2014.
Apple had used Objective-C, originally created for the Mac, for
over 20 years. Swift was created to make writing code easier
and more concise. Swift is perfect for beginners and has
lowered the barriers so that anyone can make apps.
Swift Language
fast, modern, safe,
interactive programming
language
cleaner, easier to read
than the bizarre syntax of
Objective-C.
no semicolons required
(with one statement per
line)
Initial Requirements
A Macintosh computer
Register as an Apple Developer
Need an Apple ID and register at http://
developer.apple.com/programs/register
Install Xcode
iOS Simulator
No camera or video
access
$99/year to enroll in iOS
Developer program to
test on real iOS devices/
submit to App store
Prototyping
https://popapp.in/
https://proto.io/
https://www.flinto.com/
http://www.invisionapp.com/
Basically capture sketches with camera and define tap
areas and transitions to target pages
Users try out prototypes using a shared web link
Prototyping with Keynote
Keynotpia — mock templates
http://keynotopia.com/keynote-mockups-templates/
Xcode
Playground
Like a console — try
out code and view live
execution of that code
Optionals
func findStockCode(company: String) -> String? {
if (company == "Apple") {
return "AAPL"
} else if (company == "Google") {
return "GOOG"
}
return nil
}
var stockCode:String? = findStockCode("Facebook")
let text = "Stock Code - "
let message = text + stockCode // compile-time error
println(message)
Unwrapping Optionals
var stockCode:String? = findStockCode("Facebook")
let text = "Stock Code - "
if stockCode{
let message = text + stockCode! // force unwrap
println(message)
}
Optional Chaining
class Stock {
var code: String?
var price: Double?
func findStockCode(company: String) -> Stock? {
if (company == “Apple”) {
let aapl: Stock = Stock()
aapl.code = “AAPL”
aapl.price = 90.32
return aapl
} else if (company == “Google”) {
let goog: Stock = Stock()
goog.code = “GOOG”
goog.price = 556.36
return goog
}
return nil
}
Optional Chaining
if let stock = findStockCode(“Facebook”) {
if let sharePrice = stock.price{
let totalCost = sharePrice * 100
println(totalCost)
}
}
Auto Layout
build apps to support all
screen resolutions across
iPhone and iPad models
of hardware
Retina display:

1 point = 2 pixels
iOS handles translation
between points and
pixels
Auto Layout Constraints
Example: button centered horizontally and vertically
regardless of screen resolution and orientation
(landscape/portrait)
Two constraints defined:

center horizontally

center vertically
In Xcode you use the Auto layout menu or Control-drag
Shift-Option click storyboard to see previews without
running the simulator(s)
Auto Layout Options
Align — create alignment constraints, such as aligning
the left edges of two views
Pin — create spacing constraints, such as defining the
width of a UI control
Issues — resolve layout issues; Xcode senses when
placement or layout dynamics violate a constraint
Resizing — specify how resizing affects constraints
Protocols
foundation classes in iOS such as UITableView are
organized into frameworks (such as UIKit)
UITableViewDelegate and UITableViewDataSource

are protocols in Swift. This is similar to an interface or 

contract in normal OOP constructs.
Implementing Protocols
Interface/Protocol requires the data source and
number of rows to display
tableView(_:numberOfRowsInSection:)
tableView(_:cellForRowAtIndexPath:)
dequeueReusableCellWithIdentifier method
retrieves a reusable table cell from the queue with the
cell identifier defined in the Storyboard. That way,
memory is not allocated for each row of data, but is
reused.
Hide Status Bar
In your view controller code add this method:
Constraining a Table View
Go to the storyboard and select the table view. In the Auto
Layout menu, click the Pin button to open the Pin Tool
menu. Select each of the dashed red line symbols. Once
selected, the dashed red line turns to a solid red line. Click
the “Add 4 Constraints” button to define 4 spacing
constraints for each side of the UITableView. In particular,
we want to ensure that the bottom of the UITableView
doesn’t go beyond the Bottom Layout Guide. If you
expand the constraints items in Document Outline, you’ll
find two horizontal space constraints and two vertical
constraints. The two horizontal space constraints ensures
that the left & right side of table view will stretch to the
edge of the view controllers. The vertical constraints are
used to resolve the 3.5-inch screen issues.
Delegation
The delegate pattern is very common in iOS programming.
Each delegate is responsible for a specific role or task to
keep the system simple and clean. Whenever an object
needs to perform a certain task, it depends on another
object to handle it. This is known as “separation of
concerns” in software design.
The UITableView class applies this design concept. The two
protocols are designed for different purposes. The
UITableViewDataSource defines methods that are used for
managing table data. It relies on the delegate to provide the
table data. On the other hand, the UITableViewDelegate
protocol deals with the section headings and footers of the
UITableView, plus, handles the table row selection and cell
reordering.
Which methods to implement in UITableViewDelegate?
Online iOS Developer Reference
https://developer.apple.com/library/ios/navigation/
Access documentation right from Xcode with control-
command-? while cursor on a class or protocol
Handling Table Row Selection
tableView(_:didSelectRowAtIndexPath:)
MVC and SoC
“At the heart of MVC, and the idea that was the most
influential to later frameworks, is what I call Separated
Presentation. The idea behind Separated Presentation is to
make a clear division between domain objects that model
our perception of the real world, and presentation objects
that are the GUI elements we see on the screen. Domain
objects should be completely self contained and work
without reference to the presentation, they should also be
able to support multiple presentations, possibly
simultaneously. This approach was also an important part of
the Unix culture, and continues today allowing many
applications to be manipulated through both a graphical and
command-line interface.” —Martin Fowler
http://www.martinfowler.com/eaaDev/uiArchs.html#ModelViewController
Model – responsible for holding the data or any operations
on the data. The model can be as simple as an array object
that stores all the table data. Add, update and delete are
examples of the operations. These operations are usually
known as business rules. 



View – manages the visual display of information. For
example, UITableView shows information in a list format. Or
the UIButton that appears on screen is another example.


Controller – the bridge between model and view. It
translates the user interaction from the view (e.g. tap) into
appropriate action to be performed in the model. For
example, the user taps a delete button in the view.
Consequently, the controller triggers a delete operation in the
model. Once finished, the controller requests the view to
refresh itself so as to reflect the update of the data model.
Scene and Segue
Navigation Controller — a UI component like Table View
which provides a drill-down hierarchical interface
Embed a view controller within the Navigation Controller and
create the segue (transition) between scenes in Interface
Builder in the Storyboard
scene within Storyboard is a single view controller and its
view
each scene has a dock with action and outlet
connections between the view controller and the view
Segue sits between scenes and manages the transition
between scenes — like “push” and “modal”
Navigation Bar Appearance
UINavigationBar.appearance().barTintColor =
UIColor(red: 231.0/255.0, green: 95.0/255.0, blue:
53.0/255.0, alpha: 0.3)



UINavigationBar.appearance().tintColor =
UIColor.whiteColor()



if let barFont = uiFont(name: “AvenirNextCondensed-
DemiBold”, size: 22.0){
UINavigationBar.appearance().titleTextAttributes =
[NSForegroundColorAttributeName:UIColor.whiteColor(),
NSFontAttributeName:barFont]
}
http://iosfonts.com
Hiding Navigation Bar
RestaurantTableViewController.swift:

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.hidesBarsOnSwipe = true
}



DetailViewController.swift:

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.hidesBarsOnSwipe =
false
self.navigationController?.setNavigationBarHidden
(false, animated: true)
}
Setting Status Bar Style
Global app change: Disable “View controller-based status bar
appearance” and set status bar style in AppDelegate method
didFinishLaunchingWithOptions



UIApplication.sharedApplication().statusBarStyle = .LightContent
View controller specific by overriding preferredStatusBarStyle
method:



override func preferredStatusBarStyle() ->
UIStatusBarStyle {

return .LightContent

}
For global change, set boolean value to “NO”
Enabling Self Sizing Cells
tableView.estimatedRowHeight = 36.0 // set height to
existing prototype cell
tableView.rowHeight =
UITableViewAutomaticDimension //set to default iOS
row height
Requires AutoLayout to be configured
Add code to controller’s (Detail View Controller in this
case) viewDidLoad method
References
Ng, S. Beginning IOS 8 Programming With Swift. 1st ed. AppCoda
Limited, 2014. Print.
Nepster, J. The Swift Programming Language. 1st ed. Jay Nepster, 2015.
Print.
Derico, S. (2015) Introducing iOS 8. 1st ed. Sebastopol, CA: O’Reilly
Media, Inc.
Nahavandipoor, V. (2015) iOS 8 Swift Programming Cookbook. 1st
ed. Sebastopol, CA: O’Reilly Media, Inc.
Deitel, P., et al. (2015) iOS 8 for Programmers. 3rd ed. Upper Saddle
River, NJ: Prentice Hall.

More Related Content

What's hot

Appium Mobile Testing: Nakov at BurgasConf - July 2021
Appium Mobile Testing: Nakov at BurgasConf - July 2021Appium Mobile Testing: Nakov at BurgasConf - July 2021
Appium Mobile Testing: Nakov at BurgasConf - July 2021Svetlin Nakov
 
Smartface ile Crossplatform Uygulama Geliştirme
Smartface ile Crossplatform Uygulama GeliştirmeSmartface ile Crossplatform Uygulama Geliştirme
Smartface ile Crossplatform Uygulama GeliştirmeMobile İstanbul
 
Android development basics
Android development basicsAndroid development basics
Android development basicsPramesh Gautam
 
Exploring the internal state of user interfaces using sikuli
Exploring the internal state of user interfaces using sikuliExploring the internal state of user interfaces using sikuli
Exploring the internal state of user interfaces using sikuliGermiya K Jose
 
Android development session 5 - Debug android studio
Android development   session 5 - Debug android studioAndroid development   session 5 - Debug android studio
Android development session 5 - Debug android studioFarabi Technology Middle East
 
#Code2Create:: Introduction to App Development in Flutter with Dart
#Code2Create:: Introduction to App Development in Flutter with Dart#Code2Create:: Introduction to App Development in Flutter with Dart
#Code2Create:: Introduction to App Development in Flutter with DartGDGKuwaitGoogleDevel
 
Role of java in android app development
Role of java in android app developmentRole of java in android app development
Role of java in android app developmentRahul Rana
 
打造你的第一個iPhone APP
打造你的第一個iPhone APP打造你的第一個iPhone APP
打造你的第一個iPhone APP彼得潘 Pan
 
Creating the first app with android studio
Creating the first app with android studioCreating the first app with android studio
Creating the first app with android studioParinita03
 
Anroid Tutorial Beginner level By SAMRAT TAYADE
Anroid Tutorial Beginner level By SAMRAT TAYADE Anroid Tutorial Beginner level By SAMRAT TAYADE
Anroid Tutorial Beginner level By SAMRAT TAYADE Samrat Tayade
 
Building iOS App Project & Architecture
Building iOS App Project & ArchitectureBuilding iOS App Project & Architecture
Building iOS App Project & ArchitectureMassimo Oliviero
 
iOS Developer Interview Questions
iOS Developer Interview QuestionsiOS Developer Interview Questions
iOS Developer Interview QuestionsClark Davidson
 
Ios-training-institute-in-mumbai
Ios-training-institute-in-mumbaiIos-training-institute-in-mumbai
Ios-training-institute-in-mumbaivibrantuser
 
Ios-training-institute-in-mumbai
Ios-training-institute-in-mumbaiIos-training-institute-in-mumbai
Ios-training-institute-in-mumbaivibrantuser
 
Android Development Made Easy - With Sample Project
Android Development Made Easy - With Sample ProjectAndroid Development Made Easy - With Sample Project
Android Development Made Easy - With Sample ProjectJoemarie Amparo
 
Basic android development
Basic android developmentBasic android development
Basic android developmentUpanya Singh
 
StackLabs-DataDriven Labs - iPhone App Development Training in Mohali
StackLabs-DataDriven Labs - iPhone App Development  Training in MohaliStackLabs-DataDriven Labs - iPhone App Development  Training in Mohali
StackLabs-DataDriven Labs - iPhone App Development Training in MohaliArcadian Learning
 
Android development training
Android development trainingAndroid development training
Android development trainingmaheswarimahi18
 
Different Android Test Automation Frameworks - What Works You the Best?
Different Android Test Automation Frameworks - What Works You the Best?Different Android Test Automation Frameworks - What Works You the Best?
Different Android Test Automation Frameworks - What Works You the Best?Bitbar
 

What's hot (20)

Appium Mobile Testing: Nakov at BurgasConf - July 2021
Appium Mobile Testing: Nakov at BurgasConf - July 2021Appium Mobile Testing: Nakov at BurgasConf - July 2021
Appium Mobile Testing: Nakov at BurgasConf - July 2021
 
Smartface ile Crossplatform Uygulama Geliştirme
Smartface ile Crossplatform Uygulama GeliştirmeSmartface ile Crossplatform Uygulama Geliştirme
Smartface ile Crossplatform Uygulama Geliştirme
 
Architecting iOS Project
Architecting iOS ProjectArchitecting iOS Project
Architecting iOS Project
 
Android development basics
Android development basicsAndroid development basics
Android development basics
 
Exploring the internal state of user interfaces using sikuli
Exploring the internal state of user interfaces using sikuliExploring the internal state of user interfaces using sikuli
Exploring the internal state of user interfaces using sikuli
 
Android development session 5 - Debug android studio
Android development   session 5 - Debug android studioAndroid development   session 5 - Debug android studio
Android development session 5 - Debug android studio
 
#Code2Create:: Introduction to App Development in Flutter with Dart
#Code2Create:: Introduction to App Development in Flutter with Dart#Code2Create:: Introduction to App Development in Flutter with Dart
#Code2Create:: Introduction to App Development in Flutter with Dart
 
Role of java in android app development
Role of java in android app developmentRole of java in android app development
Role of java in android app development
 
打造你的第一個iPhone APP
打造你的第一個iPhone APP打造你的第一個iPhone APP
打造你的第一個iPhone APP
 
Creating the first app with android studio
Creating the first app with android studioCreating the first app with android studio
Creating the first app with android studio
 
Anroid Tutorial Beginner level By SAMRAT TAYADE
Anroid Tutorial Beginner level By SAMRAT TAYADE Anroid Tutorial Beginner level By SAMRAT TAYADE
Anroid Tutorial Beginner level By SAMRAT TAYADE
 
Building iOS App Project & Architecture
Building iOS App Project & ArchitectureBuilding iOS App Project & Architecture
Building iOS App Project & Architecture
 
iOS Developer Interview Questions
iOS Developer Interview QuestionsiOS Developer Interview Questions
iOS Developer Interview Questions
 
Ios-training-institute-in-mumbai
Ios-training-institute-in-mumbaiIos-training-institute-in-mumbai
Ios-training-institute-in-mumbai
 
Ios-training-institute-in-mumbai
Ios-training-institute-in-mumbaiIos-training-institute-in-mumbai
Ios-training-institute-in-mumbai
 
Android Development Made Easy - With Sample Project
Android Development Made Easy - With Sample ProjectAndroid Development Made Easy - With Sample Project
Android Development Made Easy - With Sample Project
 
Basic android development
Basic android developmentBasic android development
Basic android development
 
StackLabs-DataDriven Labs - iPhone App Development Training in Mohali
StackLabs-DataDriven Labs - iPhone App Development  Training in MohaliStackLabs-DataDriven Labs - iPhone App Development  Training in Mohali
StackLabs-DataDriven Labs - iPhone App Development Training in Mohali
 
Android development training
Android development trainingAndroid development training
Android development training
 
Different Android Test Automation Frameworks - What Works You the Best?
Different Android Test Automation Frameworks - What Works You the Best?Different Android Test Automation Frameworks - What Works You the Best?
Different Android Test Automation Frameworks - What Works You the Best?
 

Similar to Swift

Mobile Application Development -Lecture 07 & 08.pdf
Mobile Application Development -Lecture 07 & 08.pdfMobile Application Development -Lecture 07 & 08.pdf
Mobile Application Development -Lecture 07 & 08.pdfAbdullahMunir32
 
ITE 1122_ AWT and SWING.pptx
ITE 1122_ AWT  and SWING.pptxITE 1122_ AWT  and SWING.pptx
ITE 1122_ AWT and SWING.pptxudithaisur
 
Publication Non Visual Components
Publication Non Visual ComponentsPublication Non Visual Components
Publication Non Visual Componentssatyres
 
GUI design using JAVAFX.ppt
GUI design using JAVAFX.pptGUI design using JAVAFX.ppt
GUI design using JAVAFX.pptTabassumMaktum
 
Manual Layout Revisited
Manual Layout RevisitedManual Layout Revisited
Manual Layout Revisitedgillygize
 
Android apps development
Android apps developmentAndroid apps development
Android apps developmentMonir Zzaman
 
Model-Driven Engineering of User Interfaces: Promises, Successes, Failures, a...
Model-Driven Engineering of User Interfaces: Promises, Successes, Failures, a...Model-Driven Engineering of User Interfaces: Promises, Successes, Failures, a...
Model-Driven Engineering of User Interfaces: Promises, Successes, Failures, a...Jean Vanderdonckt
 
Session 8 - Xcode 5 and interface builder for iOS 7 application
Session 8 - Xcode 5 and interface builder for iOS 7 applicationSession 8 - Xcode 5 and interface builder for iOS 7 application
Session 8 - Xcode 5 and interface builder for iOS 7 applicationVu Tran Lam
 
[PBO] Pertemuan 12 - Pemrograman Android
[PBO] Pertemuan 12 - Pemrograman Android[PBO] Pertemuan 12 - Pemrograman Android
[PBO] Pertemuan 12 - Pemrograman Androidrizki adam kurniawan
 
Model View Presenter (MVP) In Aspnet
Model View Presenter (MVP) In AspnetModel View Presenter (MVP) In Aspnet
Model View Presenter (MVP) In Aspnetrainynovember12
 
Advanced java lab swing mvc awt
Advanced java lab swing mvc awtAdvanced java lab swing mvc awt
Advanced java lab swing mvc awtvishal choudhary
 
iOS Development (Part 3) - Additional GUI Components
iOS Development (Part 3) - Additional GUI ComponentsiOS Development (Part 3) - Additional GUI Components
iOS Development (Part 3) - Additional GUI ComponentsAsim Rais Siddiqui
 
Better User Experience with .NET
Better User Experience with .NETBetter User Experience with .NET
Better User Experience with .NETPeter Gfader
 

Similar to Swift (20)

Mobile Application Development -Lecture 07 & 08.pdf
Mobile Application Development -Lecture 07 & 08.pdfMobile Application Development -Lecture 07 & 08.pdf
Mobile Application Development -Lecture 07 & 08.pdf
 
Introduction of Xcode
Introduction of XcodeIntroduction of Xcode
Introduction of Xcode
 
iOS Development (Part 2)
iOS Development (Part 2)iOS Development (Part 2)
iOS Development (Part 2)
 
04 objective-c session 4
04  objective-c session 404  objective-c session 4
04 objective-c session 4
 
GUI_part_1.pptx
GUI_part_1.pptxGUI_part_1.pptx
GUI_part_1.pptx
 
ITE 1122_ AWT and SWING.pptx
ITE 1122_ AWT  and SWING.pptxITE 1122_ AWT  and SWING.pptx
ITE 1122_ AWT and SWING.pptx
 
Publication Non Visual Components
Publication Non Visual ComponentsPublication Non Visual Components
Publication Non Visual Components
 
GUI design using JAVAFX.ppt
GUI design using JAVAFX.pptGUI design using JAVAFX.ppt
GUI design using JAVAFX.ppt
 
Neha
NehaNeha
Neha
 
Manual Layout Revisited
Manual Layout RevisitedManual Layout Revisited
Manual Layout Revisited
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
 
Model-Driven Engineering of User Interfaces: Promises, Successes, Failures, a...
Model-Driven Engineering of User Interfaces: Promises, Successes, Failures, a...Model-Driven Engineering of User Interfaces: Promises, Successes, Failures, a...
Model-Driven Engineering of User Interfaces: Promises, Successes, Failures, a...
 
Session 8 - Xcode 5 and interface builder for iOS 7 application
Session 8 - Xcode 5 and interface builder for iOS 7 applicationSession 8 - Xcode 5 and interface builder for iOS 7 application
Session 8 - Xcode 5 and interface builder for iOS 7 application
 
[PBO] Pertemuan 12 - Pemrograman Android
[PBO] Pertemuan 12 - Pemrograman Android[PBO] Pertemuan 12 - Pemrograman Android
[PBO] Pertemuan 12 - Pemrograman Android
 
Java lab lecture 2
Java  lab  lecture 2Java  lab  lecture 2
Java lab lecture 2
 
Model View Presenter (MVP) In Aspnet
Model View Presenter (MVP) In AspnetModel View Presenter (MVP) In Aspnet
Model View Presenter (MVP) In Aspnet
 
Advanced java lab swing mvc awt
Advanced java lab swing mvc awtAdvanced java lab swing mvc awt
Advanced java lab swing mvc awt
 
iOS Development (Part 3) - Additional GUI Components
iOS Development (Part 3) - Additional GUI ComponentsiOS Development (Part 3) - Additional GUI Components
iOS Development (Part 3) - Additional GUI Components
 
Better User Experience with .NET
Better User Experience with .NETBetter User Experience with .NET
Better User Experience with .NET
 
Authoring metaphors
Authoring metaphorsAuthoring metaphors
Authoring metaphors
 

More from Larry Ball

Comp325 v1 ww-ball-2-1
Comp325 v1 ww-ball-2-1Comp325 v1 ww-ball-2-1
Comp325 v1 ww-ball-2-1Larry Ball
 
Object Oriented PHP Overview
Object Oriented PHP OverviewObject Oriented PHP Overview
Object Oriented PHP OverviewLarry Ball
 
EISA Considerations for Web Application Security
EISA Considerations for Web Application SecurityEISA Considerations for Web Application Security
EISA Considerations for Web Application SecurityLarry Ball
 

More from Larry Ball (6)

Angular js
Angular jsAngular js
Angular js
 
Comp325 v1 ww-ball-2-1
Comp325 v1 ww-ball-2-1Comp325 v1 ww-ball-2-1
Comp325 v1 ww-ball-2-1
 
Php debugging
Php debuggingPhp debugging
Php debugging
 
Object Oriented PHP Overview
Object Oriented PHP OverviewObject Oriented PHP Overview
Object Oriented PHP Overview
 
EISA Considerations for Web Application Security
EISA Considerations for Web Application SecurityEISA Considerations for Web Application Security
EISA Considerations for Web Application Security
 
jQueryUI
 jQueryUI jQueryUI
jQueryUI
 

Recently uploaded

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

Recently uploaded (7)

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

Swift

  • 1. Text Swift Programming for iOS A Modern Alternative to Objective-C
  • 2. What is Swift? Swift is a new programming language created by Apple as the language of their future. Swift was originally announced during the Apple Worldwide Developer Conference in June of 2014. Apple had used Objective-C, originally created for the Mac, for over 20 years. Swift was created to make writing code easier and more concise. Swift is perfect for beginners and has lowered the barriers so that anyone can make apps.
  • 3. Swift Language fast, modern, safe, interactive programming language cleaner, easier to read than the bizarre syntax of Objective-C. no semicolons required (with one statement per line)
  • 4. Initial Requirements A Macintosh computer Register as an Apple Developer Need an Apple ID and register at http:// developer.apple.com/programs/register Install Xcode
  • 5. iOS Simulator No camera or video access $99/year to enroll in iOS Developer program to test on real iOS devices/ submit to App store
  • 6. Prototyping https://popapp.in/ https://proto.io/ https://www.flinto.com/ http://www.invisionapp.com/ Basically capture sketches with camera and define tap areas and transitions to target pages Users try out prototypes using a shared web link
  • 7. Prototyping with Keynote Keynotpia — mock templates http://keynotopia.com/keynote-mockups-templates/
  • 8. Xcode Playground Like a console — try out code and view live execution of that code
  • 9. Optionals func findStockCode(company: String) -> String? { if (company == "Apple") { return "AAPL" } else if (company == "Google") { return "GOOG" } return nil } var stockCode:String? = findStockCode("Facebook") let text = "Stock Code - " let message = text + stockCode // compile-time error println(message)
  • 10. Unwrapping Optionals var stockCode:String? = findStockCode("Facebook") let text = "Stock Code - " if stockCode{ let message = text + stockCode! // force unwrap println(message) }
  • 11. Optional Chaining class Stock { var code: String? var price: Double? func findStockCode(company: String) -> Stock? { if (company == “Apple”) { let aapl: Stock = Stock() aapl.code = “AAPL” aapl.price = 90.32 return aapl } else if (company == “Google”) { let goog: Stock = Stock() goog.code = “GOOG” goog.price = 556.36 return goog } return nil }
  • 12. Optional Chaining if let stock = findStockCode(“Facebook”) { if let sharePrice = stock.price{ let totalCost = sharePrice * 100 println(totalCost) } }
  • 13. Auto Layout build apps to support all screen resolutions across iPhone and iPad models of hardware Retina display:
 1 point = 2 pixels iOS handles translation between points and pixels
  • 14. Auto Layout Constraints Example: button centered horizontally and vertically regardless of screen resolution and orientation (landscape/portrait) Two constraints defined:
 center horizontally
 center vertically In Xcode you use the Auto layout menu or Control-drag Shift-Option click storyboard to see previews without running the simulator(s)
  • 15. Auto Layout Options Align — create alignment constraints, such as aligning the left edges of two views Pin — create spacing constraints, such as defining the width of a UI control Issues — resolve layout issues; Xcode senses when placement or layout dynamics violate a constraint Resizing — specify how resizing affects constraints
  • 16.
  • 17. Protocols foundation classes in iOS such as UITableView are organized into frameworks (such as UIKit)
  • 18. UITableViewDelegate and UITableViewDataSource
 are protocols in Swift. This is similar to an interface or 
 contract in normal OOP constructs.
  • 19. Implementing Protocols Interface/Protocol requires the data source and number of rows to display tableView(_:numberOfRowsInSection:) tableView(_:cellForRowAtIndexPath:)
  • 20. dequeueReusableCellWithIdentifier method retrieves a reusable table cell from the queue with the cell identifier defined in the Storyboard. That way, memory is not allocated for each row of data, but is reused.
  • 21. Hide Status Bar In your view controller code add this method:
  • 22. Constraining a Table View Go to the storyboard and select the table view. In the Auto Layout menu, click the Pin button to open the Pin Tool menu. Select each of the dashed red line symbols. Once selected, the dashed red line turns to a solid red line. Click the “Add 4 Constraints” button to define 4 spacing constraints for each side of the UITableView. In particular, we want to ensure that the bottom of the UITableView doesn’t go beyond the Bottom Layout Guide. If you expand the constraints items in Document Outline, you’ll find two horizontal space constraints and two vertical constraints. The two horizontal space constraints ensures that the left & right side of table view will stretch to the edge of the view controllers. The vertical constraints are used to resolve the 3.5-inch screen issues.
  • 23.
  • 24. Delegation The delegate pattern is very common in iOS programming. Each delegate is responsible for a specific role or task to keep the system simple and clean. Whenever an object needs to perform a certain task, it depends on another object to handle it. This is known as “separation of concerns” in software design. The UITableView class applies this design concept. The two protocols are designed for different purposes. The UITableViewDataSource defines methods that are used for managing table data. It relies on the delegate to provide the table data. On the other hand, the UITableViewDelegate protocol deals with the section headings and footers of the UITableView, plus, handles the table row selection and cell reordering.
  • 25. Which methods to implement in UITableViewDelegate? Online iOS Developer Reference https://developer.apple.com/library/ios/navigation/ Access documentation right from Xcode with control- command-? while cursor on a class or protocol Handling Table Row Selection
  • 27. MVC and SoC “At the heart of MVC, and the idea that was the most influential to later frameworks, is what I call Separated Presentation. The idea behind Separated Presentation is to make a clear division between domain objects that model our perception of the real world, and presentation objects that are the GUI elements we see on the screen. Domain objects should be completely self contained and work without reference to the presentation, they should also be able to support multiple presentations, possibly simultaneously. This approach was also an important part of the Unix culture, and continues today allowing many applications to be manipulated through both a graphical and command-line interface.” —Martin Fowler http://www.martinfowler.com/eaaDev/uiArchs.html#ModelViewController
  • 28. Model – responsible for holding the data or any operations on the data. The model can be as simple as an array object that stores all the table data. Add, update and delete are examples of the operations. These operations are usually known as business rules. 
 
 View – manages the visual display of information. For example, UITableView shows information in a list format. Or the UIButton that appears on screen is another example. 
 Controller – the bridge between model and view. It translates the user interaction from the view (e.g. tap) into appropriate action to be performed in the model. For example, the user taps a delete button in the view. Consequently, the controller triggers a delete operation in the model. Once finished, the controller requests the view to refresh itself so as to reflect the update of the data model.
  • 29. Scene and Segue Navigation Controller — a UI component like Table View which provides a drill-down hierarchical interface Embed a view controller within the Navigation Controller and create the segue (transition) between scenes in Interface Builder in the Storyboard scene within Storyboard is a single view controller and its view each scene has a dock with action and outlet connections between the view controller and the view Segue sits between scenes and manages the transition between scenes — like “push” and “modal”
  • 30.
  • 31.
  • 32. Navigation Bar Appearance UINavigationBar.appearance().barTintColor = UIColor(red: 231.0/255.0, green: 95.0/255.0, blue: 53.0/255.0, alpha: 0.3)
 
 UINavigationBar.appearance().tintColor = UIColor.whiteColor()
 
 if let barFont = uiFont(name: “AvenirNextCondensed- DemiBold”, size: 22.0){ UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor(), NSFontAttributeName:barFont] } http://iosfonts.com
  • 33. Hiding Navigation Bar RestaurantTableViewController.swift:
 override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) self.navigationController?.hidesBarsOnSwipe = true }
 
 DetailViewController.swift:
 override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) self.navigationController?.hidesBarsOnSwipe = false self.navigationController?.setNavigationBarHidden (false, animated: true) }
  • 34. Setting Status Bar Style Global app change: Disable “View controller-based status bar appearance” and set status bar style in AppDelegate method didFinishLaunchingWithOptions
 
 UIApplication.sharedApplication().statusBarStyle = .LightContent View controller specific by overriding preferredStatusBarStyle method:
 
 override func preferredStatusBarStyle() -> UIStatusBarStyle {
 return .LightContent
 }
  • 35. For global change, set boolean value to “NO”
  • 36. Enabling Self Sizing Cells tableView.estimatedRowHeight = 36.0 // set height to existing prototype cell tableView.rowHeight = UITableViewAutomaticDimension //set to default iOS row height Requires AutoLayout to be configured Add code to controller’s (Detail View Controller in this case) viewDidLoad method
  • 37. References Ng, S. Beginning IOS 8 Programming With Swift. 1st ed. AppCoda Limited, 2014. Print. Nepster, J. The Swift Programming Language. 1st ed. Jay Nepster, 2015. Print. Derico, S. (2015) Introducing iOS 8. 1st ed. Sebastopol, CA: O’Reilly Media, Inc. Nahavandipoor, V. (2015) iOS 8 Swift Programming Cookbook. 1st ed. Sebastopol, CA: O’Reilly Media, Inc. Deitel, P., et al. (2015) iOS 8 for Programmers. 3rd ed. Upper Saddle River, NJ: Prentice Hall.