SlideShare uma empresa Scribd logo
1 de 22
Swift 
Programming in 
DevelopinigO AppSs using Swift
iOS 8- New 
Features 
App Extensions - for sharing, photo editing, storage, 
custom keyboards (yay!) and much more 
Touch ID - forget registration and login, Touch ID 
authentication is here 
Games - many improvements to SpriteKit, SceneKit, 
OpenGL and a new framework Metal - for high 
performance in games 
Health Kit - a new framework for managing health-related 
info. Make way for revolutionary health apps
iOS 8- New 
Features 
Home Kit - communicate with connected devices 
(you don’t need to go to the switch now) 
Handoff - seamless continuity of activities across 
devices 
Photos - there is so much more you can do with 
Photos now And much more 
Sharing documents between apps 
More inclusive notifications 
Better search
Why Swift?
What Apple says 
Fast - performance wise, Swift is much faster than 
Objective-C 
Modern - borrows from Haskell, Ruby, Javascript - 
skill barrier greatly lowered 
Interactive - a Playground allows programmers to 
experiment with Swift code and see results 
immediately - no building and running
What developers say 
The announcement of Swift got mixed 
reactions
Show me the code!
Some key points 
Declaration and implementation are in the same file 
(no .h and .m files) 
Project size is largely reduced with Swift 
Swift auto-detects data types 
The code does not use semi-colons 
Braces are compulsory for if-else conditions
Variables (and type 
inference) 
//variables 
var name: String = "Jane Doe" 
var year: Int = 2014 
var isFast: Bool = true 
//Data type detection 
name = "John Doe" 
year = 2016 
isFast = false 
//Data type detection 
var name = "Jane Doe" 
var year = 2014 
var isFast = true
Constants 
//constants 
let name: String = "Jane Doe" 
let year: Int = 2014 
let isFast: Bool = true 
//These will give an error 
name = "John Doe" 
year = 2016 
isFast = false
String Operations 
let hello = "Hello" 
let world = "World" 
let firstString = hello + " " + world //Will print Hello World 
let a = 4, b = 5 
println ("(a) * (b) = (a * b)") //Will print 4 * 5 = 20 
isFast = false
Arrays and Dictionaries 
//Typed arrays 
var typedList: String[] = ["Yes", "No", "Cancel"] 
typedList += ["OK"] //typedList - Yes, No, Cancel, OK 
//Mixed objects in an array 
var mixedList: String[] = ["India", 40.5, 3, false] 
//Dictionaries 
var comments = ["article1":4, "article2":6, "article3":0] 
comments["article4"] = 5; 
comments += ["article5":2, "article6":8]
Accessing Collections 
//Arrays 
typedList.insert("Later", atIndex:0) //typedList - Later, Yes... 
typedList.removeAtIndex(0) //typedList - Yes, No... 
typedList.append("Later") //typedList - Yes, No...Later 
typedList.removeLast() 
//Dictionaries 
let numberOfComments = comments["article4"] //will be 5
Tuples 
//Functions return more than 1 values as tuples 
let result = (404, "Not found") 
let code = result.0 //will be 404 
let status = result.1 //will be “Not found” 
//Defining functions 
func getStatus (var1:String, var2:String)->(Int, String) 
//Calling function 
var result:(code:Int, status:String) = 
self.getStatus(var1: "googleegoo.com", var2: "http") 
print("Result is (result.code) - (result.status)")
//if statements 
if val == 0 { 
//Some code here 
} else if val == 1 { 
//Some code here 
} else { 
//Some code here 
} 
//switch cases 
switch val { 
case 1, 3, 5: println ("odd"); 
case: 2, 4, 6: println ("even"); 
case: 7...9: println ("7, 8, 9"); 
default: println ("other"); 
} 
Conditions
Conditions 
//switch with where clause and tuples 
switch rgb { 
... 
case let (r,g,b) where r==g && g==b: println("GREY"); 
default: println ("colored"); 
} 
//while loop 
while !finished {//Some code here} 
//for loop and for in 
for var i=0; i<10; i++ {//Some code here} 
for num in 1...10 {//iterate from 1 to 10} 
for num in 1..10 {//iterate from 1 to 9, not 10 - just 2 dots here}
Playground 
Run a project without compiling 
Run as you type (has its disadvantages) 
Error symbols show as you type your code 
Quick look button shows graphical display for a 
piece of code
There’s a lot more to 
Swift 
Classes and structures, Protocols 
Optional and non-optional parameters 
Properties and methods 
Getters and Setters 
Property Observers 
Closures
There’s a lot more to 
Swift 
Designated and convenience initializers 
Labeled statements 
Lazy stored properties 
Downcasting 
Class methods 
Extensions
Mapping Obj-C to Swift 
- changes to func 
+ changes to class func 
# define changes to let 
#pragma changes to //MARK : 
No init and initWith 
Change complex macros to functions 
let myCustomColor = 
UIColor(red:0.5,green:0.5,blue:0.0,alpha:1.0)
References 
https://developer.apple.com/library/prerelease/ios/documentation/http://www.raywenderlich.com/74438/swift-tutorial- 
a-quick-start 
https://www.bloc.io/swiftris-build-your-first 
-ios-game-with-swift
What to get your iOS 
app developed with 
Swift? 
Contact us for a FREE 15-minute consultation 
http://newgenapps.com/contact/ 
Skype: lata.nga / newgenapps 
Phone: +1 415 800 4445

Mais conteúdo relacionado

Mais procurados

iOS Development - A Beginner Guide
iOS Development - A Beginner GuideiOS Development - A Beginner Guide
iOS Development - A Beginner GuideAndri Yadi
 
20 Facts about Swift programming language
20 Facts about Swift programming language20 Facts about Swift programming language
20 Facts about Swift programming languageRohit Tirkey
 
Kotlin - A Programming Language
Kotlin - A Programming Language Kotlin - A Programming Language
Kotlin - A Programming Language Mobio Solutions
 
Introduction to Java
Introduction to Java Introduction to Java
Introduction to Java Hitesh-Java
 
Comparative Study On Mobile Operating Systems
  Comparative Study On Mobile Operating Systems   Comparative Study On Mobile Operating Systems
Comparative Study On Mobile Operating Systems Hardik Jain
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Manoj Ellappan
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming LanguageCihad Horuzoğlu
 
iOS Development, with Swift and XCode
iOS Development, with Swift and XCodeiOS Development, with Swift and XCode
iOS Development, with Swift and XCodeWan Leung Wong
 
Devportal Information Architecture: A 4-step Method
Devportal Information Architecture: A 4-step MethodDevportal Information Architecture: A 4-step Method
Devportal Information Architecture: A 4-step MethodPronovix
 
Pentesting iOS Applications
Pentesting iOS ApplicationsPentesting iOS Applications
Pentesting iOS Applicationsjasonhaddix
 
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
Swift Tutorial Part 1. The Complete Guide For Swift Programming LanguageSwift Tutorial Part 1. The Complete Guide For Swift Programming Language
Swift Tutorial Part 1. The Complete Guide For Swift Programming LanguageHossam Ghareeb
 
Mobile application development
Mobile application developmentMobile application development
Mobile application developmentEric Cattoir
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to SwiftGiordano Scalzo
 
Kotlin Language powerpoint show file
Kotlin Language powerpoint show fileKotlin Language powerpoint show file
Kotlin Language powerpoint show fileSaurabh Tripathi
 

Mais procurados (20)

iOS Development - A Beginner Guide
iOS Development - A Beginner GuideiOS Development - A Beginner Guide
iOS Development - A Beginner Guide
 
20 Facts about Swift programming language
20 Facts about Swift programming language20 Facts about Swift programming language
20 Facts about Swift programming language
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
Kotlin - A Programming Language
Kotlin - A Programming Language Kotlin - A Programming Language
Kotlin - A Programming Language
 
Introduction to Java
Introduction to Java Introduction to Java
Introduction to Java
 
Comparative Study On Mobile Operating Systems
  Comparative Study On Mobile Operating Systems   Comparative Study On Mobile Operating Systems
Comparative Study On Mobile Operating Systems
 
Ios development
Ios developmentIos development
Ios development
 
Introduction to Kotlin
Introduction to KotlinIntroduction to Kotlin
Introduction to Kotlin
 
Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1Basic iOS Training with SWIFT - Part 1
Basic iOS Training with SWIFT - Part 1
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
 
iOS Development, with Swift and XCode
iOS Development, with Swift and XCodeiOS Development, with Swift and XCode
iOS Development, with Swift and XCode
 
Devportal Information Architecture: A 4-step Method
Devportal Information Architecture: A 4-step MethodDevportal Information Architecture: A 4-step Method
Devportal Information Architecture: A 4-step Method
 
Pentesting iOS Applications
Pentesting iOS ApplicationsPentesting iOS Applications
Pentesting iOS Applications
 
Android with kotlin course
Android with kotlin courseAndroid with kotlin course
Android with kotlin course
 
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
Swift Tutorial Part 1. The Complete Guide For Swift Programming LanguageSwift Tutorial Part 1. The Complete Guide For Swift Programming Language
Swift Tutorial Part 1. The Complete Guide For Swift Programming Language
 
Android vs Ios
Android vs Ios Android vs Ios
Android vs Ios
 
Mobile application development
Mobile application developmentMobile application development
Mobile application development
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to Swift
 
Kotlin
KotlinKotlin
Kotlin
 
Kotlin Language powerpoint show file
Kotlin Language powerpoint show fileKotlin Language powerpoint show file
Kotlin Language powerpoint show file
 

Destaque

Build Your First iOS App With Swift
Build Your First iOS App With SwiftBuild Your First iOS App With Swift
Build Your First iOS App With SwiftEdureka!
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming LanguageGiuseppe Arici
 
The Breakout Sales Startups of 2017
The Breakout Sales Startups of 2017The Breakout Sales Startups of 2017
The Breakout Sales Startups of 2017Troops
 
NUS iOS Swift Talk
NUS iOS Swift TalkNUS iOS Swift Talk
NUS iOS Swift TalkGabriel Lim
 
360 degree quality assurance solution for apps
360 degree quality assurance solution for apps360 degree quality assurance solution for apps
360 degree quality assurance solution for appsAnurag Rastogi
 
ES6 patterns in the wild
ES6 patterns in the wildES6 patterns in the wild
ES6 patterns in the wildJoe Morgan
 
Introduccion a Data Science
Introduccion a Data ScienceIntroduccion a Data Science
Introduccion a Data ScienceSpanishPASSVC
 
Swift3 generic
Swift3 genericSwift3 generic
Swift3 genericEunjoo Im
 
iOS 10 & XCode 8, Swift 3.0 features and changes
iOS 10 & XCode 8, Swift 3.0 features and changesiOS 10 & XCode 8, Swift 3.0 features and changes
iOS 10 & XCode 8, Swift 3.0 features and changesManjula Jonnalagadda
 
Swift - the future of iOS app development
Swift - the future of iOS app developmentSwift - the future of iOS app development
Swift - the future of iOS app developmentopenak
 
The Swift Programming Language with iOS App
The Swift Programming Language with iOS AppThe Swift Programming Language with iOS App
The Swift Programming Language with iOS AppMindfire Solutions
 
Aplicaciones e impacto de la informatica en la Sociedad Actual
Aplicaciones e impacto de la informatica en la Sociedad Actual Aplicaciones e impacto de la informatica en la Sociedad Actual
Aplicaciones e impacto de la informatica en la Sociedad Actual Montserrat PG
 
Jsm2013,598,sweitzer,randomization metrics,v2,aug08
Jsm2013,598,sweitzer,randomization metrics,v2,aug08Jsm2013,598,sweitzer,randomization metrics,v2,aug08
Jsm2013,598,sweitzer,randomization metrics,v2,aug08Dennis Sweitzer
 
Medidata Customer Only Event - Global Symposium Highlights
Medidata Customer Only Event - Global Symposium HighlightsMedidata Customer Only Event - Global Symposium Highlights
Medidata Customer Only Event - Global Symposium HighlightsDonna Locke
 
Medidata AMUG Meeting / Presentation 2013
Medidata AMUG Meeting / Presentation 2013Medidata AMUG Meeting / Presentation 2013
Medidata AMUG Meeting / Presentation 2013Brock Heinz
 
Tools, Frameworks, & Swift for iOS
Tools, Frameworks, & Swift for iOSTools, Frameworks, & Swift for iOS
Tools, Frameworks, & Swift for iOSTeri Grossheim
 

Destaque (20)

360 Degree Quality Assurance Solution
360 Degree Quality Assurance Solution360 Degree Quality Assurance Solution
360 Degree Quality Assurance Solution
 
How to ensure your iOS apps are NOT rejected
How to ensure your iOS apps are NOT rejectedHow to ensure your iOS apps are NOT rejected
How to ensure your iOS apps are NOT rejected
 
Build Your First iOS App With Swift
Build Your First iOS App With SwiftBuild Your First iOS App With Swift
Build Your First iOS App With Swift
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
 
The Breakout Sales Startups of 2017
The Breakout Sales Startups of 2017The Breakout Sales Startups of 2017
The Breakout Sales Startups of 2017
 
NUS iOS Swift Talk
NUS iOS Swift TalkNUS iOS Swift Talk
NUS iOS Swift Talk
 
360 degree quality assurance solution for apps
360 degree quality assurance solution for apps360 degree quality assurance solution for apps
360 degree quality assurance solution for apps
 
ES6 patterns in the wild
ES6 patterns in the wildES6 patterns in the wild
ES6 patterns in the wild
 
¿Conoces swift?
¿Conoces swift?¿Conoces swift?
¿Conoces swift?
 
Introduccion a Data Science
Introduccion a Data ScienceIntroduccion a Data Science
Introduccion a Data Science
 
Swift3 generic
Swift3 genericSwift3 generic
Swift3 generic
 
iOS 10 & XCode 8, Swift 3.0 features and changes
iOS 10 & XCode 8, Swift 3.0 features and changesiOS 10 & XCode 8, Swift 3.0 features and changes
iOS 10 & XCode 8, Swift 3.0 features and changes
 
Swift - the future of iOS app development
Swift - the future of iOS app developmentSwift - the future of iOS app development
Swift - the future of iOS app development
 
The Swift Programming Language with iOS App
The Swift Programming Language with iOS AppThe Swift Programming Language with iOS App
The Swift Programming Language with iOS App
 
iOSMumbai Meetup Keynote
iOSMumbai Meetup KeynoteiOSMumbai Meetup Keynote
iOSMumbai Meetup Keynote
 
Aplicaciones e impacto de la informatica en la Sociedad Actual
Aplicaciones e impacto de la informatica en la Sociedad Actual Aplicaciones e impacto de la informatica en la Sociedad Actual
Aplicaciones e impacto de la informatica en la Sociedad Actual
 
Jsm2013,598,sweitzer,randomization metrics,v2,aug08
Jsm2013,598,sweitzer,randomization metrics,v2,aug08Jsm2013,598,sweitzer,randomization metrics,v2,aug08
Jsm2013,598,sweitzer,randomization metrics,v2,aug08
 
Medidata Customer Only Event - Global Symposium Highlights
Medidata Customer Only Event - Global Symposium HighlightsMedidata Customer Only Event - Global Symposium Highlights
Medidata Customer Only Event - Global Symposium Highlights
 
Medidata AMUG Meeting / Presentation 2013
Medidata AMUG Meeting / Presentation 2013Medidata AMUG Meeting / Presentation 2013
Medidata AMUG Meeting / Presentation 2013
 
Tools, Frameworks, & Swift for iOS
Tools, Frameworks, & Swift for iOSTools, Frameworks, & Swift for iOS
Tools, Frameworks, & Swift for iOS
 

Semelhante a Developing iOS apps with Swift

What every beginning developer should know
What every beginning developer should knowWhat every beginning developer should know
What every beginning developer should knowAndy Lester
 
Introduction to programming - class 11
Introduction to programming - class 11Introduction to programming - class 11
Introduction to programming - class 11Paul Brebner
 
Stuff you didn't know about action script
Stuff you didn't know about action scriptStuff you didn't know about action script
Stuff you didn't know about action scriptChristophe Herreman
 
ESWHO, ESWHAT, ESWOW -- FEDucation -- IBM Design
ESWHO, ESWHAT, ESWOW -- FEDucation -- IBM DesignESWHO, ESWHAT, ESWOW -- FEDucation -- IBM Design
ESWHO, ESWHAT, ESWOW -- FEDucation -- IBM DesignJosh Black
 
Your Library Sucks, and why you should use it.
Your Library Sucks, and why you should use it.Your Library Sucks, and why you should use it.
Your Library Sucks, and why you should use it.Peter Higgins
 
RubyMotion
RubyMotionRubyMotion
RubyMotionMark
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Wsloffenauer
 
GDI Seattle - Intro to JavaScript Class 1
GDI Seattle - Intro to JavaScript Class 1GDI Seattle - Intro to JavaScript Class 1
GDI Seattle - Intro to JavaScript Class 1Heather Rock
 
FITC '14 Toronto - Technology, a means to an end
FITC '14 Toronto - Technology, a means to an endFITC '14 Toronto - Technology, a means to an end
FITC '14 Toronto - Technology, a means to an endThibault Imbert
 
Technology: A Means to an End with Thibault Imbert
Technology: A Means to an End with Thibault ImbertTechnology: A Means to an End with Thibault Imbert
Technology: A Means to an End with Thibault ImbertFITC
 
Clean Code Development
Clean Code DevelopmentClean Code Development
Clean Code DevelopmentPeter Gfader
 
2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScriptJohannes Hoppe
 
2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScriptJohannes Hoppe
 
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014hwilming
 
React Native Evening
React Native EveningReact Native Evening
React Native EveningTroy Miles
 

Semelhante a Developing iOS apps with Swift (20)

ES6 at PayPal
ES6 at PayPalES6 at PayPal
ES6 at PayPal
 
JavaScript ES6
JavaScript ES6JavaScript ES6
JavaScript ES6
 
What every beginning developer should know
What every beginning developer should knowWhat every beginning developer should know
What every beginning developer should know
 
Introduction to programming - class 11
Introduction to programming - class 11Introduction to programming - class 11
Introduction to programming - class 11
 
Stuff you didn't know about action script
Stuff you didn't know about action scriptStuff you didn't know about action script
Stuff you didn't know about action script
 
ESWHO, ESWHAT, ESWOW -- FEDucation -- IBM Design
ESWHO, ESWHAT, ESWOW -- FEDucation -- IBM DesignESWHO, ESWHAT, ESWOW -- FEDucation -- IBM Design
ESWHO, ESWHAT, ESWOW -- FEDucation -- IBM Design
 
Your Library Sucks, and why you should use it.
Your Library Sucks, and why you should use it.Your Library Sucks, and why you should use it.
Your Library Sucks, and why you should use it.
 
RubyMotion
RubyMotionRubyMotion
RubyMotion
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
 
GDI Seattle - Intro to JavaScript Class 1
GDI Seattle - Intro to JavaScript Class 1GDI Seattle - Intro to JavaScript Class 1
GDI Seattle - Intro to JavaScript Class 1
 
Fantom and Tales
Fantom and TalesFantom and Tales
Fantom and Tales
 
FITC '14 Toronto - Technology, a means to an end
FITC '14 Toronto - Technology, a means to an endFITC '14 Toronto - Technology, a means to an end
FITC '14 Toronto - Technology, a means to an end
 
Technology: A Means to an End with Thibault Imbert
Technology: A Means to an End with Thibault ImbertTechnology: A Means to an End with Thibault Imbert
Technology: A Means to an End with Thibault Imbert
 
Clean Code Development
Clean Code DevelopmentClean Code Development
Clean Code Development
 
2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript
 
2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript
 
JavaScript Needn't Hurt!
JavaScript Needn't Hurt!JavaScript Needn't Hurt!
JavaScript Needn't Hurt!
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
 
React Native Evening
React Native EveningReact Native Evening
React Native Evening
 

Developing iOS apps with Swift

  • 1. Swift Programming in DevelopinigO AppSs using Swift
  • 2. iOS 8- New Features App Extensions - for sharing, photo editing, storage, custom keyboards (yay!) and much more Touch ID - forget registration and login, Touch ID authentication is here Games - many improvements to SpriteKit, SceneKit, OpenGL and a new framework Metal - for high performance in games Health Kit - a new framework for managing health-related info. Make way for revolutionary health apps
  • 3. iOS 8- New Features Home Kit - communicate with connected devices (you don’t need to go to the switch now) Handoff - seamless continuity of activities across devices Photos - there is so much more you can do with Photos now And much more Sharing documents between apps More inclusive notifications Better search
  • 5. What Apple says Fast - performance wise, Swift is much faster than Objective-C Modern - borrows from Haskell, Ruby, Javascript - skill barrier greatly lowered Interactive - a Playground allows programmers to experiment with Swift code and see results immediately - no building and running
  • 6. What developers say The announcement of Swift got mixed reactions
  • 7. Show me the code!
  • 8. Some key points Declaration and implementation are in the same file (no .h and .m files) Project size is largely reduced with Swift Swift auto-detects data types The code does not use semi-colons Braces are compulsory for if-else conditions
  • 9. Variables (and type inference) //variables var name: String = "Jane Doe" var year: Int = 2014 var isFast: Bool = true //Data type detection name = "John Doe" year = 2016 isFast = false //Data type detection var name = "Jane Doe" var year = 2014 var isFast = true
  • 10. Constants //constants let name: String = "Jane Doe" let year: Int = 2014 let isFast: Bool = true //These will give an error name = "John Doe" year = 2016 isFast = false
  • 11. String Operations let hello = "Hello" let world = "World" let firstString = hello + " " + world //Will print Hello World let a = 4, b = 5 println ("(a) * (b) = (a * b)") //Will print 4 * 5 = 20 isFast = false
  • 12. Arrays and Dictionaries //Typed arrays var typedList: String[] = ["Yes", "No", "Cancel"] typedList += ["OK"] //typedList - Yes, No, Cancel, OK //Mixed objects in an array var mixedList: String[] = ["India", 40.5, 3, false] //Dictionaries var comments = ["article1":4, "article2":6, "article3":0] comments["article4"] = 5; comments += ["article5":2, "article6":8]
  • 13. Accessing Collections //Arrays typedList.insert("Later", atIndex:0) //typedList - Later, Yes... typedList.removeAtIndex(0) //typedList - Yes, No... typedList.append("Later") //typedList - Yes, No...Later typedList.removeLast() //Dictionaries let numberOfComments = comments["article4"] //will be 5
  • 14. Tuples //Functions return more than 1 values as tuples let result = (404, "Not found") let code = result.0 //will be 404 let status = result.1 //will be “Not found” //Defining functions func getStatus (var1:String, var2:String)->(Int, String) //Calling function var result:(code:Int, status:String) = self.getStatus(var1: "googleegoo.com", var2: "http") print("Result is (result.code) - (result.status)")
  • 15. //if statements if val == 0 { //Some code here } else if val == 1 { //Some code here } else { //Some code here } //switch cases switch val { case 1, 3, 5: println ("odd"); case: 2, 4, 6: println ("even"); case: 7...9: println ("7, 8, 9"); default: println ("other"); } Conditions
  • 16. Conditions //switch with where clause and tuples switch rgb { ... case let (r,g,b) where r==g && g==b: println("GREY"); default: println ("colored"); } //while loop while !finished {//Some code here} //for loop and for in for var i=0; i<10; i++ {//Some code here} for num in 1...10 {//iterate from 1 to 10} for num in 1..10 {//iterate from 1 to 9, not 10 - just 2 dots here}
  • 17. Playground Run a project without compiling Run as you type (has its disadvantages) Error symbols show as you type your code Quick look button shows graphical display for a piece of code
  • 18. There’s a lot more to Swift Classes and structures, Protocols Optional and non-optional parameters Properties and methods Getters and Setters Property Observers Closures
  • 19. There’s a lot more to Swift Designated and convenience initializers Labeled statements Lazy stored properties Downcasting Class methods Extensions
  • 20. Mapping Obj-C to Swift - changes to func + changes to class func # define changes to let #pragma changes to //MARK : No init and initWith Change complex macros to functions let myCustomColor = UIColor(red:0.5,green:0.5,blue:0.0,alpha:1.0)
  • 22. What to get your iOS app developed with Swift? Contact us for a FREE 15-minute consultation http://newgenapps.com/contact/ Skype: lata.nga / newgenapps Phone: +1 415 800 4445