SlideShare una empresa de Scribd logo
1 de 22
Descargar para leer sin conexión
Introduction to Swift
@RoelCastano
June 23, 2014
Swift vs Objective-C
#include <stdio.h>
int main()

{

	 printf(“hello, worldn”);

	 return 0;

}
println(“hello, world”)
Variables
let dogName: String = “Cinnamon”
!
var age: Double = 8.5
!
var inferredType = “String”
!
let 🐝 = “Bee”
for character in “string” {
	 println(character)
}
// s
// t
// r
// i
// n
// g
!
———————————————-
!
let a = 3, b = 5
let stringResult = “(a) times (b) is (a * b)”
more strings
var variableSting = “Apple”
variableString += “ and Pixar”
// variableString is now “Apple and Pixar”
!
let constantString = “Apple”
constantString += “ and Microsoft”
// constant can’t be changed
!
//casting

let label = "The width is "

let width = 94_000_00

let widthLabel: String = label + String(width)
!
Optionals and TypeAlias
//Optionals
!
var dogAge = "123".toInt()
if dogAge { //is either nil or Int
    dogAge! //now it is an Int
}
!
var someValue: String?
someValue = "Fido"
!
someValue = nil
//typealias
!
typealias 👬 = Double
var size: 👬 = 12.2
!
typealias Point = (Int, Int)
let origin: Point = (0, 0)
Tuples
//unnamed tuples
var luckyNumbers: = (3, 8, 21)
luckyNumbers.2
//21
!
//named tuples
var myDog:(Int, Int, Bool) = (age: 8, isAFemale: true)
var (age,_) = myDog
age
//6
!
!
Arrays
/*
Notes:
These arrays can only be of one types, not like
NSArray or NSDictionary, which can have any object.
*/
!
//array (String[] optional)
let emptyArray = String[]()
!
var shoppingList: String[] = ["catfish", "water", "tulips", "blue paint"] //prefered
var numberList: Array<Int> = [1,2,3,4,5]
var numberList2 = [11,22,33,44,55] //preferred
!
shoppingList.append("milk")
!
for (index, object) in enumerate(shoppingList){
println("The object #(index) is a (object)")
}
!
var possibleNames = Array(count: 10, repeatedValue: "BRO")
Dictionaries
//dictionary
let emptyDictionary = Dictionary<String, Float>()
!
var occupations = [
"Malcolm": "Captain",
"Kaylee": "Mechanic",
]
occupations["Jayne"] = "Public Relations"
occupations.updateValue("Chief", forKey:"Malcolm")
occupations.removeValueForKey("Kaylee")
occupations
!
var employees = Array(occupations.keys)
!
for (name, occupation) in occupations
{
println("Name: (name) n Occupation: (occupation)")
}
!
If-Else and Switch
// If-Else
!
var optionalString: String? =
"Hello"
optionalString == nil
!
var optionalName: String? = nil
var greeting = "Hello!"
if let name = optionalName {
greeting = "Hello, (name)"
} else {
let name = String("Some Name")
}
// Switch
!
let vegetable = "red pepper"
switch vegetable {
!
case “celery":
let vegetableComment = "Add some
raisins and make ants on a log.”
!
case "cucumber", "watercress":
let vegetableComment = "That would
make a good tea sandwich.”
!
case let x where x.hasSuffix("pepper"):
let vegetableComment = "Is it a
spicy (x)?”
!
default:
let vegetableComment = "Everything
tastes good in soup.”
}
For Loop
let interestingNumbers = [
"Prime": [2, 3, 5, 7, 11, 13],
"Fibonacci": [1, 1, 2, 3, 5,
8],
"Square": [1, 4, 9, 16, 25],
]
var largest = 0
var largestKind:String? = nil
for (kind, numbers) in
interestingNumbers {
for number in numbers {
if number > largest {
largest = number
largestKind = kind
}
}
}
largest //25
largestKind //square
var firstForLoop = 0
for i in 0..3 {
firstForLoop += i
}
firstForLoop // 3
!
————————————————————————————————
!
var firstForLoop = 0
for i in 0...3 {
secondForLoop += i
}
secondForLoop // 6
Functions
func count(string: String) -> (vowels: Int, consonants: Int, others: Int) {
var vowels = 0, consonants = 0, others = 0
for character in string {
switch String(character).lowercaseString {
case "a", "e", "i", "o", "u":
++vowels
case "b", "c", "d", "f", "g", "h", "j", "k", "l", "m",
"n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z":
++consonants
default:
++others
}
}
return (vowels, consonants, others)
}
!
let total = count("some arbitrary string!")
let finalString = "(total.vowels) vowels and (total.consonants)
consonants"
// prints "6 vowels and 13 consonants"
Functions and Generics
func swapTwoInts(inout a: Int, inout b: Int) {
let temporaryA = a
a = b
b = temporaryA
}
!
var someInt = 3
var anotherInt = 107
swapTwoInts(&someInt, &anotherInt)
let newInts = "someInt is now (someInt), and anotherInt is now
(anotherInt)"
// prints "someInt is now 107, and anotherInt is now 3"
Generics
!
func swapTwoValues<T>(inout a: T, inout b: T) {
let temporaryA = a
a = b
b = temporaryA
}
!
var designer = "Lentes"
var programmer = "Alice"
swapTwoValues(&designer, &programmer)
let newTeam = "designer is now (designer), and programmer is
now (programmer)"
// prints "designer is now Alice, and programmer is now Lentes"
Structures vs Classes
Consider Structure when:
Encapsulate simple data values
Values would be copied rather
than referenced.
Any properties stored by the
structure are themselves value
types.
Ex. Geometric Shapes,
Coordinates, Person.
Consider Classes when:
Inheritance should be used.
Need more than one
reference to the same
instance
Check or Interpret the type
of a class at runtime
Ex. Real life complex objects.
Classes
class Vehicle {
var numberOfWheels: Int
var maxPassengers: Int
func description() -> String {
return "(numberOfWheels) wheels; up to (maxPassengers) passengers"
}
init() {
numberOfWheels = 0
maxPassengers = 1
}
}
class Bicycle: Vehicle {
init() {
super.init()
numberOfWheels = 2
}
}
class Tandem: Bicycle {
init() {
super.init()
maxPassengers = 2
}
}
let tandem = Tandem()
println("Tandem: 
(tandem.description())”)
// Tandem: 2 wheels; up to 2
passengers
Method Overriding
class Car: Vehicle {
var speed: Double = 0.0
init() {
super.init()
maxPassengers = 5
numberOfWheels = 4
}
override func description() -> String {
return super.description() + "; "
+ "traveling at (speed) mph"
}
}
let car = Car()
println("Car: (car.description())")
// Car: 4 wheels; up to 5 passengers; traveling at 0.0 mph
Property Overriding
class SpeedLimitedCar: Car {
override var speed: Double {
get {
return super.speed
}
set {
super.speed = min(newValue, 40.0)
}
}
}
!
let limitedCar = SpeedLimitedCar()
limitedCar.speed = 60.0
println("SpeedLimitedCar: (limitedCar.description())")
// SpeedLimitedCar: 4 wheels; up to 5 passengers; traveling at 40.0 mph
Structs
struct Color {
let red = 0.0, green = 0.0, blue = 0.0
init(red: Double, green: Double, blue: Double) {
self.red = red
self.green = green
self.blue = blue
}
}
!
!
let magenta = Color(red: 1.0, green: 0.0, blue: 1.0)
!
Protocols
protocol FullyNamed {
var fullName: String { get }
}
!
struct Person: FullyNamed {
var fullName: String
}
!
let john = Person(fullName: "John Appleseed")
// john.fullName is "John Appleseed"
!
more protocols
!
!
protocol RandomNumberGenerator {
func random() -> Double
}
!
class Dice {
let sides: Int
let generator: RandomNumberGenerator
init(sides: Int, generator: RandomNumberGenerator) {
self.sides = sides
self.generator = generator
}
func roll() -> Int {
return Int(generator.random() * Double(sides)) + 1
}
}
!
protocol TextRepresentable {
func asText() -> String
}
!
extension Dice: TextRepresentable {
func asText() -> String {
return "A (sides)-sided dice"
}
}
Facts
First app built on Swift was the WWDC App.
You can use Swift, C, and Objective-C in parallel.
The book “The Swift Programming Language” was
downloaded 370,000 times on one day.
References
Swift Tutorial Part 3: Tuples, Protocols, Delegates, and
Table Views. http://www.raywenderlich.com/75289/swift-
tutorial-part-3-tuples-protocols-delegates-table-views
An Introduction To Object-Oriented Programming in Swift.
http://blog.codeclimate.com/blog/2014/06/19/oo-swift/
A Few Interesting Things In Swift http://
www.slideshare.net/SmartLogic/a-few-interesting-
things-in-swift

Más contenido relacionado

La actualidad más candente

Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in javakamal kotecha
 
Core java concepts
Core java  conceptsCore java  concepts
Core java conceptsRam132
 
Introduction to basics of java
Introduction to basics of javaIntroduction to basics of java
Introduction to basics of javavinay arora
 
Functional programming
Functional programmingFunctional programming
Functional programmingijcd
 
gRPC: The Story of Microservices at Square
gRPC: The Story of Microservices at SquaregRPC: The Story of Microservices at Square
gRPC: The Story of Microservices at SquareApigee | Google Cloud
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Atif AbbAsi
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java ProgrammingRavi Kant Sahu
 
Chapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptxChapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptxXhelalSpahiu
 
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
 

La actualidad más candente (20)

java Features
java Featuresjava Features
java Features
 
Swift Introduction
Swift IntroductionSwift Introduction
Swift Introduction
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
 
Dart ppt
Dart pptDart ppt
Dart ppt
 
Java
JavaJava
Java
 
phases of a compiler
 phases of a compiler phases of a compiler
phases of a compiler
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
Introduction to basics of java
Introduction to basics of javaIntroduction to basics of java
Introduction to basics of java
 
Introduction to JAVA
Introduction to JAVAIntroduction to JAVA
Introduction to JAVA
 
JAVA PROGRAMMING
JAVA PROGRAMMING JAVA PROGRAMMING
JAVA PROGRAMMING
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
gRPC: The Story of Microservices at Square
gRPC: The Story of Microservices at SquaregRPC: The Story of Microservices at Square
gRPC: The Story of Microservices at Square
 
core java
core javacore java
core java
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Core Java Tutorial
Core Java TutorialCore Java Tutorial
Core Java Tutorial
 
Chapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptxChapter 9 Conditional and Iterative Statements.pptx
Chapter 9 Conditional and Iterative Statements.pptx
 
C#.NET
C#.NETC#.NET
C#.NET
 
Selenium
SeleniumSelenium
Selenium
 
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
 

Similar a Introduction to Swift programming language.

Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기Suyeol Jeon
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to SwiftGiordano Scalzo
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to PerlSway Wang
 
NUS iOS Swift Talk
NUS iOS Swift TalkNUS iOS Swift Talk
NUS iOS Swift TalkGabriel Lim
 
A Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming LanguageA Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming LanguageSmartLogic
 
Adding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer ToolboxAdding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer ToolboxJeff Strauss
 
Cocoa Design Patterns in Swift
Cocoa Design Patterns in SwiftCocoa Design Patterns in Swift
Cocoa Design Patterns in SwiftMichele Titolo
 
Bologna Developer Zone - About Kotlin
Bologna Developer Zone - About KotlinBologna Developer Zone - About Kotlin
Bologna Developer Zone - About KotlinMarco Vasapollo
 
Naïveté vs. Experience
Naïveté vs. ExperienceNaïveté vs. Experience
Naïveté vs. ExperienceMike Fogus
 
An Introduction to Scala (2014)
An Introduction to Scala (2014)An Introduction to Scala (2014)
An Introduction to Scala (2014)William Narmontas
 
An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6FITC
 

Similar a Introduction to Swift programming language. (20)

Swift Study #7
Swift Study #7Swift Study #7
Swift Study #7
 
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
 
Kotlin
KotlinKotlin
Kotlin
 
Pooya Khaloo Presentation on IWMC 2015
Pooya Khaloo Presentation on IWMC 2015Pooya Khaloo Presentation on IWMC 2015
Pooya Khaloo Presentation on IWMC 2015
 
A swift introduction to Swift
A swift introduction to SwiftA swift introduction to Swift
A swift introduction to Swift
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
NUS iOS Swift Talk
NUS iOS Swift TalkNUS iOS Swift Talk
NUS iOS Swift Talk
 
A Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming LanguageA Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming Language
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
Adding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer ToolboxAdding ES6 to Your Developer Toolbox
Adding ES6 to Your Developer Toolbox
 
Intro to ruby
Intro to rubyIntro to ruby
Intro to ruby
 
Cocoa Design Patterns in Swift
Cocoa Design Patterns in SwiftCocoa Design Patterns in Swift
Cocoa Design Patterns in Swift
 
Bologna Developer Zone - About Kotlin
Bologna Developer Zone - About KotlinBologna Developer Zone - About Kotlin
Bologna Developer Zone - About Kotlin
 
Naïveté vs. Experience
Naïveté vs. ExperienceNaïveté vs. Experience
Naïveté vs. Experience
 
An Introduction to Scala (2014)
An Introduction to Scala (2014)An Introduction to Scala (2014)
An Introduction to Scala (2014)
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Php & my sql
Php & my sqlPhp & my sql
Php & my sql
 
Introduction kot iin
Introduction kot iinIntroduction kot iin
Introduction kot iin
 
An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 

Más de Icalia Labs

Building an Api the Right Way
Building an Api the Right WayBuilding an Api the Right Way
Building an Api the Right WayIcalia Labs
 
Agile practices for management
Agile practices for managementAgile practices for management
Agile practices for managementIcalia Labs
 
Building something out of Nothing
Building something out of NothingBuilding something out of Nothing
Building something out of NothingIcalia Labs
 
Furatto tertulia
Furatto tertuliaFuratto tertulia
Furatto tertuliaIcalia Labs
 
Simple but Useful Design Principles.
Simple but Useful Design Principles.Simple but Useful Design Principles.
Simple but Useful Design Principles.Icalia Labs
 
Your time saving front end workflow
Your time saving front end workflowYour time saving front end workflow
Your time saving front end workflowIcalia Labs
 
Customer Experience Basics
Customer Experience BasicsCustomer Experience Basics
Customer Experience BasicsIcalia Labs
 
Time Hacks for Work
Time Hacks for WorkTime Hacks for Work
Time Hacks for WorkIcalia Labs
 
Culture in a team
Culture in a teamCulture in a team
Culture in a teamIcalia Labs
 
Presentacion vim
Presentacion vimPresentacion vim
Presentacion vimIcalia Labs
 
Using github development process in your company
Using github development process in your companyUsing github development process in your company
Using github development process in your companyIcalia Labs
 
The Art of Pitching
The Art of PitchingThe Art of Pitching
The Art of PitchingIcalia Labs
 
Rails Best Practices
Rails Best PracticesRails Best Practices
Rails Best PracticesIcalia Labs
 
Introduccion meteor.js
Introduccion meteor.jsIntroduccion meteor.js
Introduccion meteor.jsIcalia Labs
 

Más de Icalia Labs (16)

Building an Api the Right Way
Building an Api the Right WayBuilding an Api the Right Way
Building an Api the Right Way
 
Agile practices for management
Agile practices for managementAgile practices for management
Agile practices for management
 
Building something out of Nothing
Building something out of NothingBuilding something out of Nothing
Building something out of Nothing
 
Furatto tertulia
Furatto tertuliaFuratto tertulia
Furatto tertulia
 
Simple but Useful Design Principles.
Simple but Useful Design Principles.Simple but Useful Design Principles.
Simple but Useful Design Principles.
 
Your time saving front end workflow
Your time saving front end workflowYour time saving front end workflow
Your time saving front end workflow
 
Customer Experience Basics
Customer Experience BasicsCustomer Experience Basics
Customer Experience Basics
 
Time Hacks for Work
Time Hacks for WorkTime Hacks for Work
Time Hacks for Work
 
Culture in a team
Culture in a teamCulture in a team
Culture in a team
 
Curso rails
Curso railsCurso rails
Curso rails
 
Presentacion vim
Presentacion vimPresentacion vim
Presentacion vim
 
Using github development process in your company
Using github development process in your companyUsing github development process in your company
Using github development process in your company
 
The Art of Pitching
The Art of PitchingThe Art of Pitching
The Art of Pitching
 
Rails Best Practices
Rails Best PracticesRails Best Practices
Rails Best Practices
 
Introduccion meteor.js
Introduccion meteor.jsIntroduccion meteor.js
Introduccion meteor.js
 
Rspec and Rails
Rspec and RailsRspec and Rails
Rspec and Rails
 

Último

Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
%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 tembisamasabamasaba
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
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...Shane Coughlan
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
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-learnAmarnathKambale
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
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 insideshinachiaurasa2
 

Último (20)

Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%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
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
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...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
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
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
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
 

Introduction to Swift programming language.

  • 2. Swift vs Objective-C #include <stdio.h> int main()
 {
 printf(“hello, worldn”);
 return 0;
 } println(“hello, world”)
  • 3. Variables let dogName: String = “Cinnamon” ! var age: Double = 8.5 ! var inferredType = “String” ! let 🐝 = “Bee” for character in “string” { println(character) } // s // t // r // i // n // g ! ———————————————- ! let a = 3, b = 5 let stringResult = “(a) times (b) is (a * b)”
  • 4. more strings var variableSting = “Apple” variableString += “ and Pixar” // variableString is now “Apple and Pixar” ! let constantString = “Apple” constantString += “ and Microsoft” // constant can’t be changed ! //casting
 let label = "The width is "
 let width = 94_000_00
 let widthLabel: String = label + String(width) !
  • 5. Optionals and TypeAlias //Optionals ! var dogAge = "123".toInt() if dogAge { //is either nil or Int     dogAge! //now it is an Int } ! var someValue: String? someValue = "Fido" ! someValue = nil //typealias ! typealias 👬 = Double var size: 👬 = 12.2 ! typealias Point = (Int, Int) let origin: Point = (0, 0)
  • 6. Tuples //unnamed tuples var luckyNumbers: = (3, 8, 21) luckyNumbers.2 //21 ! //named tuples var myDog:(Int, Int, Bool) = (age: 8, isAFemale: true) var (age,_) = myDog age //6 ! !
  • 7. Arrays /* Notes: These arrays can only be of one types, not like NSArray or NSDictionary, which can have any object. */ ! //array (String[] optional) let emptyArray = String[]() ! var shoppingList: String[] = ["catfish", "water", "tulips", "blue paint"] //prefered var numberList: Array<Int> = [1,2,3,4,5] var numberList2 = [11,22,33,44,55] //preferred ! shoppingList.append("milk") ! for (index, object) in enumerate(shoppingList){ println("The object #(index) is a (object)") } ! var possibleNames = Array(count: 10, repeatedValue: "BRO")
  • 8. Dictionaries //dictionary let emptyDictionary = Dictionary<String, Float>() ! var occupations = [ "Malcolm": "Captain", "Kaylee": "Mechanic", ] occupations["Jayne"] = "Public Relations" occupations.updateValue("Chief", forKey:"Malcolm") occupations.removeValueForKey("Kaylee") occupations ! var employees = Array(occupations.keys) ! for (name, occupation) in occupations { println("Name: (name) n Occupation: (occupation)") } !
  • 9. If-Else and Switch // If-Else ! var optionalString: String? = "Hello" optionalString == nil ! var optionalName: String? = nil var greeting = "Hello!" if let name = optionalName { greeting = "Hello, (name)" } else { let name = String("Some Name") } // Switch ! let vegetable = "red pepper" switch vegetable { ! case “celery": let vegetableComment = "Add some raisins and make ants on a log.” ! case "cucumber", "watercress": let vegetableComment = "That would make a good tea sandwich.” ! case let x where x.hasSuffix("pepper"): let vegetableComment = "Is it a spicy (x)?” ! default: let vegetableComment = "Everything tastes good in soup.” }
  • 10. For Loop let interestingNumbers = [ "Prime": [2, 3, 5, 7, 11, 13], "Fibonacci": [1, 1, 2, 3, 5, 8], "Square": [1, 4, 9, 16, 25], ] var largest = 0 var largestKind:String? = nil for (kind, numbers) in interestingNumbers { for number in numbers { if number > largest { largest = number largestKind = kind } } } largest //25 largestKind //square var firstForLoop = 0 for i in 0..3 { firstForLoop += i } firstForLoop // 3 ! ———————————————————————————————— ! var firstForLoop = 0 for i in 0...3 { secondForLoop += i } secondForLoop // 6
  • 11. Functions func count(string: String) -> (vowels: Int, consonants: Int, others: Int) { var vowels = 0, consonants = 0, others = 0 for character in string { switch String(character).lowercaseString { case "a", "e", "i", "o", "u": ++vowels case "b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z": ++consonants default: ++others } } return (vowels, consonants, others) } ! let total = count("some arbitrary string!") let finalString = "(total.vowels) vowels and (total.consonants) consonants" // prints "6 vowels and 13 consonants"
  • 12. Functions and Generics func swapTwoInts(inout a: Int, inout b: Int) { let temporaryA = a a = b b = temporaryA } ! var someInt = 3 var anotherInt = 107 swapTwoInts(&someInt, &anotherInt) let newInts = "someInt is now (someInt), and anotherInt is now (anotherInt)" // prints "someInt is now 107, and anotherInt is now 3"
  • 13. Generics ! func swapTwoValues<T>(inout a: T, inout b: T) { let temporaryA = a a = b b = temporaryA } ! var designer = "Lentes" var programmer = "Alice" swapTwoValues(&designer, &programmer) let newTeam = "designer is now (designer), and programmer is now (programmer)" // prints "designer is now Alice, and programmer is now Lentes"
  • 14. Structures vs Classes Consider Structure when: Encapsulate simple data values Values would be copied rather than referenced. Any properties stored by the structure are themselves value types. Ex. Geometric Shapes, Coordinates, Person. Consider Classes when: Inheritance should be used. Need more than one reference to the same instance Check or Interpret the type of a class at runtime Ex. Real life complex objects.
  • 15. Classes class Vehicle { var numberOfWheels: Int var maxPassengers: Int func description() -> String { return "(numberOfWheels) wheels; up to (maxPassengers) passengers" } init() { numberOfWheels = 0 maxPassengers = 1 } } class Bicycle: Vehicle { init() { super.init() numberOfWheels = 2 } } class Tandem: Bicycle { init() { super.init() maxPassengers = 2 } } let tandem = Tandem() println("Tandem: (tandem.description())”) // Tandem: 2 wheels; up to 2 passengers
  • 16. Method Overriding class Car: Vehicle { var speed: Double = 0.0 init() { super.init() maxPassengers = 5 numberOfWheels = 4 } override func description() -> String { return super.description() + "; " + "traveling at (speed) mph" } } let car = Car() println("Car: (car.description())") // Car: 4 wheels; up to 5 passengers; traveling at 0.0 mph
  • 17. Property Overriding class SpeedLimitedCar: Car { override var speed: Double { get { return super.speed } set { super.speed = min(newValue, 40.0) } } } ! let limitedCar = SpeedLimitedCar() limitedCar.speed = 60.0 println("SpeedLimitedCar: (limitedCar.description())") // SpeedLimitedCar: 4 wheels; up to 5 passengers; traveling at 40.0 mph
  • 18. Structs struct Color { let red = 0.0, green = 0.0, blue = 0.0 init(red: Double, green: Double, blue: Double) { self.red = red self.green = green self.blue = blue } } ! ! let magenta = Color(red: 1.0, green: 0.0, blue: 1.0) !
  • 19. Protocols protocol FullyNamed { var fullName: String { get } } ! struct Person: FullyNamed { var fullName: String } ! let john = Person(fullName: "John Appleseed") // john.fullName is "John Appleseed" !
  • 20. more protocols ! ! protocol RandomNumberGenerator { func random() -> Double } ! class Dice { let sides: Int let generator: RandomNumberGenerator init(sides: Int, generator: RandomNumberGenerator) { self.sides = sides self.generator = generator } func roll() -> Int { return Int(generator.random() * Double(sides)) + 1 } } ! protocol TextRepresentable { func asText() -> String } ! extension Dice: TextRepresentable { func asText() -> String { return "A (sides)-sided dice" } }
  • 21. Facts First app built on Swift was the WWDC App. You can use Swift, C, and Objective-C in parallel. The book “The Swift Programming Language” was downloaded 370,000 times on one day.
  • 22. References Swift Tutorial Part 3: Tuples, Protocols, Delegates, and Table Views. http://www.raywenderlich.com/75289/swift- tutorial-part-3-tuples-protocols-delegates-table-views An Introduction To Object-Oriented Programming in Swift. http://blog.codeclimate.com/blog/2014/06/19/oo-swift/ A Few Interesting Things In Swift http:// www.slideshare.net/SmartLogic/a-few-interesting- things-in-swift