SlideShare a Scribd company logo
Swift Programming
Language
Hello World
println(“Hello World!”)
//var using make a variable.
var hello = “Hello”
//let using make a constants.
let world = “World!”
println(“(hello) (world)”)
Simple Values
var name = “ANIL”
//Weight type is Double.
var weight: Double = 74.4
//Correct.
var myVariable = 4
myVariable = 10
//Wrong, because myVariable type is Integer now.
var myVariable = 4
myVariable = “Four”
Simple Values
var text = “ANIL”
var number = 7
//Combining two variables to one variable.
var textNumber = text + String(number)
println(textNumber)
For - If - Else - Else If
//0,1,2,3,4,5,6,7,8,9
for var i = 0; i < 10; i++ {
println(i)
}
//1,2,3,4,5
for i in 1…5 {
println(i)
}
if condition {
/* Codes */
}
else if condition {
/* Codes */
}
else {
/* Codes */
}
Switch - Case
var str = “Swift”
//break is automatically in Swift
switch str {
case “Swift”, “swift”:
println(“Swift”)
case “Objective - C”:
println(“Objective - C”)
default:
println(“Other Language”)
}
Switch - Case
let somePoint = (2,0)
//We can giving a label.
mainSwitch: switch somePoint {
case (2,0) where somePoint.0 == 2:
println(“2,0”)
//Second case working to.
fallthrough
//x value doesn’t matter.
case (_,0):
println(“_,0”)
default:
println(“Other Point”)
}
Array - Dictionary
//Make an array.
var cities = [“Istanbul”, “Sivas”, “San Francisco”, “Seul”]
println(cities[0])
//Make a dictionary.
var cityCodes = [
“Istanbul Anadolu” : “216”,
“Istanbul Avrupa” : “212”,
“Ankara” : ”312”
]
println(cityCodes[“Istanbul Anadolu”]!)
Array
var stringArray = [“Hello”, “World”]
//Add element into the array.
stringArray.append(“Objective - C”)
//Insert element into the array.
stringArray.insert(“Apple”, atIndex: 2)
//Remove element into the array.
stringArray.removeAtIndex(3)
//Remove last element into the array.
stringArray.removeLast()
//Get element into the array.
stringArray[1]
stringArray[1…3]
//Get all elements into the array.
for (index, value) in enumerate(stringArray) {
println(“(index + 1). value is: (value)”)
}
//Get element count in the array.
stringArray.count
Array
var airports = [“SAW” : “Sabiha Gokcen Havalimani”,
“IST” : “Ataturk Havalimani”]
//Add element in the dictionary.
airports[“JFK”] = “John F Kennedy”
//Get element count in the dictionary.
airports.count
//Update element in the dictionary.
airports.updateValue(“John F Kennedy Terminal”,
forKey: “JFK”)
Dictionary
Dictionary
//Remove element in the dictionary.
airports.removeValueForKey(“JFK”)
//Get all elements into the dictionary.
for (airportCode, airport) in airports {
println(“Airport Code: (airportCode) Airport:
(airport)”)
}
//Get all keys.
var keysArray = airports.keys
//Get all values.
var valuesArray = airports.values
Functions
//Make a function.
func hello(){
println(“Hello World!”)
}
//Call a function.
hello()
//personName is parameter tag name.
func helloTo(personName name:String){
println(“Hello (name)”)
}
Functions
/*#it works, same parameter name and parameter tag
name. This function returned String value. */
func printName(#name: String) -> String{
return name
}
//This function returned Int value.
func sum(#numberOne: Int numberTwo: Int) -> Int{
return numberOne + numberTwo
}
Functions
//Tuple returns multiple value.
func sumAndCeiling(#numberOne: Int numberTwo: Int)
-> (sum: Int, ceiling: Int){
var ceiling = numberOne > numberTwo ? numberOne
: numberTwo
var sum = numberOne + numberTwo
return (sum,ceiling)
}
Functions
func double(number:Int) -> Int {
return number * 2
}
func triple(number:Int) -> Int {
return number * 3
}
func modifyInt(#number:Int modifier:Int -> Int) -> Int {
return modifier(number)
}
//Call functions
modifyInt(number: 4 modifier: double)
modifyInt(number: 4 modifier: triple)
Functions
/* This function have inner function and returned
function, buildIncrementor function returned function
and incrementor function returned Int value. */
func buildIncrementor() -> () -> Int {
var count = 0
func incrementor() -> Int{
count++
return count
}
return incrementor
}
Functions
/* Take unlimited parameter functions */
func avarage(#numbers:Int…) -> Int {
var total = 0;
for n in numbers{
total += n;
}
return total / numbers.count;
}
Structs
/* Creating Struct */
struct GeoPoint {
//Swift doesn’t like empty values
var latitude = 0.0
var longitude = 0.0
}
/* Initialize Struct */
var geoPoint = GeoPoint()
geoPoint.latitude = 44.444
geoPoint.longitude = 12.222
Classes
/* Creating Class */
class Person {
var name:String
var age:Int
//nickname:String? is optional value.
var nickname:String?
init(name:String, age:Int, nickname:String? = nil){
self.name = name
self.age = age
self.nickname = nickname
}
}
Classes
/* Creating Sub Class */
class Class : SuperClass {
var name:String
init(name:String){
self.name = name
super.init(age: age, nickname: nickname)
}
func printName(){
println(name)
}
}
Classes
/* Creating Class (Static) Method */
class MyClass {
class func printWord(#word:String) {
println(word)
}
}
/* Calling Class (Static) Method */
MyClass.printWord(word: “Hello World!”)
Enums
/* Creating Enum */
enum Direction {
case Left
case Right
case Up
case Down
}
//Call Enum Value
Direction.Right
or
var direction:Direction
direction = .Up
Enums
/* Creating Enum with Parameter(s) */
enum Computer {
//RAM, Processor
case Desktop(Int,String)
//Screen Size
case Laptop(Int)
}
//Call Enum Value with Parameter(s)
var computer = Computer.Desktop(16,”i7”)
Enums
/* Creating Enum with Int */
enum Planet:Int {
case Mercury = 1, Venus, Earth, Mars, Jupiter, Saturn,
Uranus, Neptune
}
/* Call Enum Value for Raw Value */
//Returns 3
Planet.Earth.toRaw()
//Returns Mars (Optional Value)
Planet.Earth.fromRaw(4)

More Related Content

What's hot (20)

PDF
Swift Introduction
Natasha Murashev
 
PDF
Kotlin for Android Development
Speck&Tech
 
PDF
Intro to UIKit • Made by Many
kenatmxm
 
PPTX
Lab #2: Introduction to Javascript
Walid Ashraf
 
PDF
A swift introduction to Swift
Giordano Scalzo
 
PDF
Introduction of Xcode
Dhaval Kaneria
 
PDF
Kotlin vs Java | Edureka
Edureka!
 
PDF
Data Persistence in Android with Room Library
Reinvently
 
PDF
Swift in SwiftUI
Bongwon Lee
 
PDF
JavaScript for ABAP Programmers - 1/7 Introduction
Chris Whealy
 
PPT
C# Basics
Sunil OS
 
PPTX
Introduction to Kotlin
T.M. Ishrak Hussain
 
PPT
Introduction To C#
SAMIR BHOGAYTA
 
PDF
Introduction to kotlin
NAVER Engineering
 
PDF
Testing Spark and Scala
datamantra
 
PPTX
Intro to kotlin
Tomislav Homan
 
PDF
JUnit & Mockito, first steps
Renato Primavera
 
PPSX
Introduction of java
Madishetty Prathibha
 
PPTX
Android jetpack compose | Declarative UI
Ajinkya Saswade
 
Swift Introduction
Natasha Murashev
 
Kotlin for Android Development
Speck&Tech
 
Intro to UIKit • Made by Many
kenatmxm
 
Lab #2: Introduction to Javascript
Walid Ashraf
 
A swift introduction to Swift
Giordano Scalzo
 
Introduction of Xcode
Dhaval Kaneria
 
Kotlin vs Java | Edureka
Edureka!
 
Data Persistence in Android with Room Library
Reinvently
 
Swift in SwiftUI
Bongwon Lee
 
JavaScript for ABAP Programmers - 1/7 Introduction
Chris Whealy
 
C# Basics
Sunil OS
 
Introduction to Kotlin
T.M. Ishrak Hussain
 
Introduction To C#
SAMIR BHOGAYTA
 
Introduction to kotlin
NAVER Engineering
 
Testing Spark and Scala
datamantra
 
Intro to kotlin
Tomislav Homan
 
JUnit & Mockito, first steps
Renato Primavera
 
Introduction of java
Madishetty Prathibha
 
Android jetpack compose | Declarative UI
Ajinkya Saswade
 

Viewers also liked (14)

PDF
Swift sin hype y su importancia en el 2017
Software Guru
 
DOCX
McAdams- Resume
Katey McAdams
 
PDF
Swift 2
Jens Ravens
 
PDF
Интуит. Разработка приложений для iOS. Лекция 5. Сложные Views
Глеб Тарасов
 
PPT
Swift Introduction
Savvycom Savvycom
 
PDF
Введение в разработку для iOS
Michael Dudarev
 
PPTX
Openstack Swift Introduction
Park YounSung
 
PDF
Преимущества и недостатки языка Swift
Andrey Volobuev
 
PPTX
OpenStack Swift In the Enterprise
Hostway|HOSTING
 
PDF
iOS for Android Developers (with Swift)
David Truxall
 
PDF
Initial presentation of swift (for montreal user group)
Marcos García
 
Swift sin hype y su importancia en el 2017
Software Guru
 
McAdams- Resume
Katey McAdams
 
Swift 2
Jens Ravens
 
Интуит. Разработка приложений для iOS. Лекция 5. Сложные Views
Глеб Тарасов
 
Swift Introduction
Savvycom Savvycom
 
Введение в разработку для iOS
Michael Dudarev
 
Openstack Swift Introduction
Park YounSung
 
Преимущества и недостатки языка Swift
Andrey Volobuev
 
OpenStack Swift In the Enterprise
Hostway|HOSTING
 
iOS for Android Developers (with Swift)
David Truxall
 
Initial presentation of swift (for montreal user group)
Marcos García
 
Ad

Similar to Swift Programming Language (20)

PDF
Programming Language Swift Overview
Kaz Yoshikawa
 
PDF
Swift - the future of iOS app development
openak
 
PDF
Swift Study #2
chanju Jeon
 
PDF
Quick swift tour
Kazunobu Tasaka
 
PDF
Deep Dive Into Swift
Sarath C
 
PDF
Introduction to Swift 2
Joris Timmerman
 
PDF
Swift Programming
Codemotion
 
PDF
Swift Introduction
Giuseppe Arici
 
PDF
Pooya Khaloo Presentation on IWMC 2015
Iran Entrepreneurship Association
 
PDF
NUS iOS Swift Talk
Gabriel Lim
 
PDF
Swift, swiftly
Jack Nutting
 
PPT
Swift-Programming Part 1
Mindfire Solutions
 
PPT
Developing iOS apps with Swift
New Generation Applications
 
PDF
Introduction to Swift
Matteo Battaglio
 
PDF
NSCoder Swift - An Introduction to Swift
Andreas Blick
 
PDF
Cocoa Design Patterns in Swift
Michele Titolo
 
PPTX
A Few Interesting Things in Apple's Swift Programming Language
SmartLogic
 
PDF
Swift rocks! #1
Hackraft
 
PDF
Intro toswift1
Jordan Morgan
 
PDF
Workshop Swift
Commit University
 
Programming Language Swift Overview
Kaz Yoshikawa
 
Swift - the future of iOS app development
openak
 
Swift Study #2
chanju Jeon
 
Quick swift tour
Kazunobu Tasaka
 
Deep Dive Into Swift
Sarath C
 
Introduction to Swift 2
Joris Timmerman
 
Swift Programming
Codemotion
 
Swift Introduction
Giuseppe Arici
 
Pooya Khaloo Presentation on IWMC 2015
Iran Entrepreneurship Association
 
NUS iOS Swift Talk
Gabriel Lim
 
Swift, swiftly
Jack Nutting
 
Swift-Programming Part 1
Mindfire Solutions
 
Developing iOS apps with Swift
New Generation Applications
 
Introduction to Swift
Matteo Battaglio
 
NSCoder Swift - An Introduction to Swift
Andreas Blick
 
Cocoa Design Patterns in Swift
Michele Titolo
 
A Few Interesting Things in Apple's Swift Programming Language
SmartLogic
 
Swift rocks! #1
Hackraft
 
Intro toswift1
Jordan Morgan
 
Workshop Swift
Commit University
 
Ad

Recently uploaded (20)

DOC
MRRS Strength and Durability of Concrete
CivilMythili
 
PDF
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
PPTX
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
DOCX
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
PDF
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
PPTX
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
PPTX
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
PDF
SERVERLESS PERSONAL TO-DO LIST APPLICATION
anushaashraf20
 
PDF
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
PPTX
Introduction to Design of Machine Elements
PradeepKumarS27
 
PPT
New_school_Engineering_presentation_011707.ppt
VinayKumar304579
 
PDF
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
PPTX
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PPTX
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
PPTX
MATLAB : Introduction , Features , Display Windows, Syntax, Operators, Graph...
Amity University, Patna
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PPTX
Presentation 2.pptx AI-powered home security systems Secure-by-design IoT fr...
SoundaryaBC2
 
MRRS Strength and Durability of Concrete
CivilMythili
 
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
Water Industry Process Automation & Control Monthly July 2025
Water Industry Process Automation & Control
 
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
SERVERLESS PERSONAL TO-DO LIST APPLICATION
anushaashraf20
 
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
Introduction to Design of Machine Elements
PradeepKumarS27
 
New_school_Engineering_presentation_011707.ppt
VinayKumar304579
 
MAD Unit - 1 Introduction of Android IT Department
JappanMavani
 
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
MATLAB : Introduction , Features , Display Windows, Syntax, Operators, Graph...
Amity University, Patna
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
Presentation 2.pptx AI-powered home security systems Secure-by-design IoT fr...
SoundaryaBC2
 

Swift Programming Language

  • 2. Hello World println(“Hello World!”) //var using make a variable. var hello = “Hello” //let using make a constants. let world = “World!” println(“(hello) (world)”)
  • 3. Simple Values var name = “ANIL” //Weight type is Double. var weight: Double = 74.4 //Correct. var myVariable = 4 myVariable = 10 //Wrong, because myVariable type is Integer now. var myVariable = 4 myVariable = “Four”
  • 4. Simple Values var text = “ANIL” var number = 7 //Combining two variables to one variable. var textNumber = text + String(number) println(textNumber)
  • 5. For - If - Else - Else If //0,1,2,3,4,5,6,7,8,9 for var i = 0; i < 10; i++ { println(i) } //1,2,3,4,5 for i in 1…5 { println(i) } if condition { /* Codes */ } else if condition { /* Codes */ } else { /* Codes */ }
  • 6. Switch - Case var str = “Swift” //break is automatically in Swift switch str { case “Swift”, “swift”: println(“Swift”) case “Objective - C”: println(“Objective - C”) default: println(“Other Language”) }
  • 7. Switch - Case let somePoint = (2,0) //We can giving a label. mainSwitch: switch somePoint { case (2,0) where somePoint.0 == 2: println(“2,0”) //Second case working to. fallthrough //x value doesn’t matter. case (_,0): println(“_,0”) default: println(“Other Point”) }
  • 8. Array - Dictionary //Make an array. var cities = [“Istanbul”, “Sivas”, “San Francisco”, “Seul”] println(cities[0]) //Make a dictionary. var cityCodes = [ “Istanbul Anadolu” : “216”, “Istanbul Avrupa” : “212”, “Ankara” : ”312” ] println(cityCodes[“Istanbul Anadolu”]!)
  • 9. Array var stringArray = [“Hello”, “World”] //Add element into the array. stringArray.append(“Objective - C”) //Insert element into the array. stringArray.insert(“Apple”, atIndex: 2) //Remove element into the array. stringArray.removeAtIndex(3) //Remove last element into the array. stringArray.removeLast()
  • 10. //Get element into the array. stringArray[1] stringArray[1…3] //Get all elements into the array. for (index, value) in enumerate(stringArray) { println(“(index + 1). value is: (value)”) } //Get element count in the array. stringArray.count Array
  • 11. var airports = [“SAW” : “Sabiha Gokcen Havalimani”, “IST” : “Ataturk Havalimani”] //Add element in the dictionary. airports[“JFK”] = “John F Kennedy” //Get element count in the dictionary. airports.count //Update element in the dictionary. airports.updateValue(“John F Kennedy Terminal”, forKey: “JFK”) Dictionary
  • 12. Dictionary //Remove element in the dictionary. airports.removeValueForKey(“JFK”) //Get all elements into the dictionary. for (airportCode, airport) in airports { println(“Airport Code: (airportCode) Airport: (airport)”) } //Get all keys. var keysArray = airports.keys //Get all values. var valuesArray = airports.values
  • 13. Functions //Make a function. func hello(){ println(“Hello World!”) } //Call a function. hello() //personName is parameter tag name. func helloTo(personName name:String){ println(“Hello (name)”) }
  • 14. Functions /*#it works, same parameter name and parameter tag name. This function returned String value. */ func printName(#name: String) -> String{ return name } //This function returned Int value. func sum(#numberOne: Int numberTwo: Int) -> Int{ return numberOne + numberTwo }
  • 15. Functions //Tuple returns multiple value. func sumAndCeiling(#numberOne: Int numberTwo: Int) -> (sum: Int, ceiling: Int){ var ceiling = numberOne > numberTwo ? numberOne : numberTwo var sum = numberOne + numberTwo return (sum,ceiling) }
  • 16. Functions func double(number:Int) -> Int { return number * 2 } func triple(number:Int) -> Int { return number * 3 } func modifyInt(#number:Int modifier:Int -> Int) -> Int { return modifier(number) } //Call functions modifyInt(number: 4 modifier: double) modifyInt(number: 4 modifier: triple)
  • 17. Functions /* This function have inner function and returned function, buildIncrementor function returned function and incrementor function returned Int value. */ func buildIncrementor() -> () -> Int { var count = 0 func incrementor() -> Int{ count++ return count } return incrementor }
  • 18. Functions /* Take unlimited parameter functions */ func avarage(#numbers:Int…) -> Int { var total = 0; for n in numbers{ total += n; } return total / numbers.count; }
  • 19. Structs /* Creating Struct */ struct GeoPoint { //Swift doesn’t like empty values var latitude = 0.0 var longitude = 0.0 } /* Initialize Struct */ var geoPoint = GeoPoint() geoPoint.latitude = 44.444 geoPoint.longitude = 12.222
  • 20. Classes /* Creating Class */ class Person { var name:String var age:Int //nickname:String? is optional value. var nickname:String? init(name:String, age:Int, nickname:String? = nil){ self.name = name self.age = age self.nickname = nickname } }
  • 21. Classes /* Creating Sub Class */ class Class : SuperClass { var name:String init(name:String){ self.name = name super.init(age: age, nickname: nickname) } func printName(){ println(name) } }
  • 22. Classes /* Creating Class (Static) Method */ class MyClass { class func printWord(#word:String) { println(word) } } /* Calling Class (Static) Method */ MyClass.printWord(word: “Hello World!”)
  • 23. Enums /* Creating Enum */ enum Direction { case Left case Right case Up case Down } //Call Enum Value Direction.Right or var direction:Direction direction = .Up
  • 24. Enums /* Creating Enum with Parameter(s) */ enum Computer { //RAM, Processor case Desktop(Int,String) //Screen Size case Laptop(Int) } //Call Enum Value with Parameter(s) var computer = Computer.Desktop(16,”i7”)
  • 25. Enums /* Creating Enum with Int */ enum Planet:Int { case Mercury = 1, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune } /* Call Enum Value for Raw Value */ //Returns 3 Planet.Earth.toRaw() //Returns Mars (Optional Value) Planet.Earth.fromRaw(4)