SlideShare a Scribd company logo
1
Introduction of Swift
Presenter: Waseem Ahmad, Mindfire Solutions
Date: 28/10/2014
What you will learn
Presenter: Waseem Ahmad, Mindfire Solutions
What is Swift?
Variable
Constants
Type Inference
Type Aliases
String/Character Interpolation
Array and Dictionary
Loops
Optionals, Unwrapping an Optional
Functions
Tuples
Classes
Properties
Closures
Q & A
What is Swift ?
• Swift is Apple’s modern, type-safe language for Cocoa development that
builds on the best of C and Objective-C
• Safe
• Modern
• Power
Presenter: Waseem Ahmad, Mindfire Solutions
Variables
var variableName : String = “Swift”
var version: Double = 1.0
var day: Int = 28
var isAnimated: Bool = true
Presenter: Waseem Ahmad, Mindfire Solutions
Constants &Variables
let variableName: String = “Swift”
var version: Double = 1.0
var day: Int = 28
var isAnimated: Bool = true
Pretty clear which is constant and mutable, it’s define safe code in multithreaded
environment. Make code more clear and readable.
Presenter: Waseem Ahmad, Mindfire Solutions
Constants &Variables
let variableName: String = “Swift”
var version: Double = 1.0
let day: Int = 28
let isAnimated: Bool = true
Presenter: Waseem Ahmad, Mindfire Solutions
Type Inference
let variableName = “Swift” // As String
var version = 1.0 // As Double/Float
let day = 28 // As Int
let isAnimated = true // As Boolean
Code safe, these are valuable & constant explicitly type.
Presenter: Waseem Ahmad, Mindfire Solutions
Type Aliases
An alternative name for an existing type.
typealias AudioSample = UInt16
var maxAmplitudeFound = AudioSample.min
Presenter: Waseem Ahmad, Mindfire Solutions
Unicode Names
let variableName = “Swift” // As String
var version = 1.0 // As Double/Float
let day = 28 // As Int
let isAnimated = true // As Boolean
let π = 3.1415927
let � = "emoji"�
Presenter: Waseem Ahmad, Mindfire Solutions
String
var studentName: String = “Waseem”
var studentName = “Waseem” // Inferred to be of type string
Presenter: Waseem Ahmad, Mindfire Solutions
String
var studentName: String = “Waseem”
var studentName = “Waseem” // Inferred to be of type string
var documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
documentsPath = documentsPath.stringByAppendingString(subpath)
Presenter: Waseem Ahmad, Mindfire Solutions
Character
let studentName = “Waseem"
for character in studentName {
println(character)
}
W
a
s
e
e
m
Presenter: Waseem Ahmad, Mindfire Solutions
Complex String
var name = “Waseem”
var coins = 100
Congratulations, Waseem won 100 coins.
Presenter: Waseem Ahmad, Mindfire Solutions
String Interpolation
var name = “Waseem”
var coins = 100
Congratulations, Waseem won 100 coins.
let message = “Congratulations, (name) won (coins)”.
Presenter: Waseem Ahmad, Mindfire Solutions
String Mutability
var variableString = "Mindfire"
Presenter: Waseem Ahmad, Mindfire Solutions
String Mutability
var variableString = “Mindfire"
variableString += " Solutions”
// variableString is now “Mindfire Solutions"
Presenter: Waseem Ahmad, Mindfire Solutions
String Mutability
var variableString = “Mindfire"
variableString += " Solutions”
// variableString is now “Mindfire Solutions"
let constantString = “Mindfire"
constantString += " Solutions”
// error - constantString cannot be changed
Presenter: Waseem Ahmad, Mindfire Solutions
String Mutability
var variableString = “Mindfire"
variableString += " Solutions”
// variableString is now “Mindfire Solutions"
let constantString = “Mindfire"
constantString += " Solutions”
// error - constantString cannot be changed
Presenter: Waseem Ahmad, Mindfire Solutions
Collection Type (Array &
Dictionary)
Presenter: Waseem Ahmad, Mindfire Solutions
Array and Dictionary Literals
var names = [“John”, “Bob”, "Brian", "Jack"]
Presenter: Waseem Ahmad, Mindfire Solutions
Array and Dictionary Literals
var names = [“John”, “Bob”, "Brian", “Jack"]
var numberOfLegs = ["ant": 6, "snake": 0, "cheetah": 4]
Presenter: Waseem Ahmad, Mindfire Solutions
Difference Between NSArray &
NSDictionary
- It could work with any type (String, Int etc)
- Collection are typed collection
Presenter: Waseem Ahmad, Mindfire Solutions
Typed Collection
var names = [“John”, “Bob”, "Brian", “Jack”, 123]
var names = [“John”, “Bob”, "Brian", “Jack”, function()]
Presenter: Waseem Ahmad, Mindfire Solutions
Typed Collection
var names: String[] = [“John”, “Bob”, "Brian", “Jack”]
Presenter: Waseem Ahmad, Mindfire Solutions
Typed Collection
var names = [“John”, “Bob”, "Brian", “Jack”]
// An array of String Values
var numberOfLegs = ["ant": 6, "snake": 0, "cheetah": 4]
// An Dictionary With String Keys and Int Values
Typed collection made your code safe, you well know what you are retrieving and
adding.
Presenter: Waseem Ahmad, Mindfire Solutions
Loop
while !isTrue {
print(“hello”)
}
for var i = 1; i <= 13; ++i {
print(“hello”)
}
Presenter: Waseem Ahmad, Mindfire Solutions
For-In: Strings and Characters
let studentName = “Waseem"
for character in studentName {
println(character)
}
W
a
s
e
e
m
Swift Power, we can use character & emoji in similar way.
Presenter: Waseem Ahmad, Mindfire Solutions
For-In: Ranges
for number in 1...5 { // Clause Range
println("(number) times 4 is (number * 4)")
}
1 times 4 is 4
2 times 4 is 8
3 times 4 is 12
4 times 4 is 16
5 times 4 is 20
Presenter: Waseem Ahmad, Mindfire Solutions
For-In: Ranges
for number in 0..5 { // half clause range
println("(number) times 4 is (number * 4)")
}
0 times 4 is 0
1 times 4 is 4
2 times 4 is 8
3 times 4 is 12
4 times 4 is 16
Presenter: Waseem Ahmad, Mindfire Solutions
For-In: Array
var names = [“John”, “Bob”, "Brian", "Jack"]
for name in names {
println("Hello (name)")
}
Presenter: Waseem Ahmad, Mindfire Solutions
For-In: Dictionaries
let numberOfLegs = ["ant": 6, "snake": 0, "cheetah": 4]
!
for (animalName, legCount) in numberOfLegs {
println("(animalName)s have (legCount) legs")
}
ants have 6 legs
Power of swift extracting key and value in single loop, grouping of value is a power
full feature of swift i.e Tuples
Presenter: Waseem Ahmad, Mindfire Solutions
Modification in Array
var shoppingList = ["Eggs", "Milk"]
println(shoppingList[0])
Presenter: Waseem Ahmad, Mindfire Solutions
Modification in Array
var shoppingList = ["Eggs", "Milk"]
println(shoppingList[0])
shoppingList += "Flour"
shoppingList += ["Cheese", "Butter", "Chocolate Spread"]
Presenter: Waseem Ahmad, Mindfire Solutions
Modification in Array
var shoppingList = ["Eggs", "Milk"]
shoppingList += "Flour"
shoppingList += ["Cheese", "Butter", "Chocolate Spread”]
shoppingList[0] = "Six eggs"
Presenter: Waseem Ahmad, Mindfire Solutions
Modification in Array
var shoppingList = ["Eggs", "Milk"]
shoppingList += "Flour"
shoppingList += ["Cheese", "Butter", "Chocolate Spread”]
shoppingList[0] = "Six eggs”
["Six eggs", "Milk", "Flour", "Cheese", "Butter",
"Chocolate Spread"]
shoppingList[3...5] = ["Bananas", “Apples"]
["Six eggs", "Milk", "Flour", "Bananas", “Apples"]
Presenter: Waseem Ahmad, Mindfire Solutions
Modification in Dictionary
var numberOfLegs = ["ant": 6, "snake": 0, "cheetah": 4]
numberOfLegs["spider"] = 273
Presenter: Waseem Ahmad, Mindfire Solutions
Modification in Dictionary
var numberOfLegs = ["ant": 6, "snake": 0, "cheetah": 4]
numberOfLegs["spider"] = 273
numberOfLegs["spider"] = 8
What happen if we try to fetch a value that doesn’t have in array and dictionary?
let lionLegCount = numberOfLegs[“lion”] // Nothing at all :)
Presenter: Waseem Ahmad, Mindfire Solutions
Optional
var numberOfLegs = ["ant": 6, "snake": 0, "cheetah": 4]
let lionLegCount: Int? = numberOfLegs["lion"]
Presenter: Waseem Ahmad, Mindfire Solutions
Optional
var numberOfLegs = ["ant": 6, "snake": 0, "cheetah": 4]
let lionLegCount: Int? = numberOfLegs[“lion"]
if lionLegCount == nil {
println("Lion wasn't found")
} else {
let legCount = lionLegCount! // unwrapping of optional value
println("An lion has (legCount) legs")
}
Presenter: Waseem Ahmad, Mindfire Solutions
Optional
if numberOfLegs {
let legCount = numberOfLegs!
println("An Lion has (legCount) legs")
}
Presenter: Waseem Ahmad, Mindfire Solutions
Unwrapping an Optional
if let legCount = numberOfLegs {
println("An Lion has (legCount) legs")
}
Note:- Braces are required with If :)
Presenter: Waseem Ahmad, Mindfire Solutions
Switch
switch legCount {
case 0:
println("It slithers and slides around”)
case 1:
println("It hops")
default:
println("It walks")
}
Presenter: Waseem Ahmad, Mindfire Solutions
Switch
switch sender {
case executeButton:
println("You tapped the Execute button")
case firstNameTextField:
println("You tapped the First Name text field")
default:
println("You tapped some other object")
}
Presenter: Waseem Ahmad, Mindfire Solutions
Switch
switch legCount {
case 0:
println("It slithers and slides around")!
case 1, 3, 5, 7, 9, 11, 13:
println("It limps")
case 2, 4, 6, 8, 10, 12, 14:
println("It walks")
}
// error: switch must be exhaustive
Presenter: Waseem Ahmad, Mindfire Solutions
Switch
switch legCount {
case 0:
println("It slithers and slides around")!
case 1, 3, 5, 7, 9, 11, 13:
println("It limps")
case 2, 4, 6, 8, 10, 12, 14:
println("It walks”)
default:
println("It walks")
}
Presenter: Waseem Ahmad, Mindfire Solutions
Matching Value Ranges
switch legCount {
case 0:
println("It slithers and slides around")!
case 1…8:
println("It has few lags")
default:
println("It walks")
}
Presenter: Waseem Ahmad, Mindfire Solutions
Functions
func sayHello() {
println("Hello!")
}
Presenter: Waseem Ahmad, Mindfire Solutions
Functions with Parameters
func sayHello(name: String) {
println("Hello (name)!")
}
Presenter: Waseem Ahmad, Mindfire Solutions
Default Parameter Values
func sayHello(name: String = "World") {
println("Hello (name)!")
}
sayHello() // Hello World
sayHello(“Team”) // Hello Team
Presenter: Waseem Ahmad, Mindfire Solutions
Returning Values
func greetingMsg(name: String = "World") -> String {
return "Hello " + name
}
let greeting = greetingMsg()
Presenter: Waseem Ahmad, Mindfire Solutions
Returning Multiple Values
func getUsernInfo() -> (Int, String) {
return (25, “John”)
}
Presenter: Waseem Ahmad, Mindfire Solutions
Tuples
-Grouping a values
-Value could be any type
(3.79, 3.99, 4.19) // (Double, Double, Double)
(404, "Not found")
(2, "banana", 0.72)
-Tuple is not an replacement of structure but this is best when needs to
return multiple values like from function
func getUsernInfo() -> (Int, String) {
return (25, “John”)
}
Presenter: Waseem Ahmad, Mindfire Solutions
Decomposing of Tuples
func getUsernInfo() -> (Int, String) {
return (25, “John”)
}
let (age, name) = getUsernInfo()
println(“This is (name) and my age is (age)")
Presenter: Waseem Ahmad, Mindfire Solutions
Decomposing of Tuples
func getUsernInfo() -> (Int, String) {
return (25, “John”)
}
let (age, name) = getUsernInfo()
let (age: Int, name: String) = getUsernInfo()
println(“This is (name) and my age is (age)")
If you only need some of the tuple’s values, ignore parts of the tuple with an
underscore (_) when you decompose the tuple:
let (age, _) = getUsernInfo()
Presenter: Waseem Ahmad, Mindfire Solutions
Named Values in a Tuple
func getUsernInfo() -> (age: Int, name: String) {
return (25, “John”)
}
let userInfo = getUsernInfo()
println(“This is (userInfo.name) and my age is (userInfo.age)”)
Presenter: Waseem Ahmad, Mindfire Solutions
Classes
class Student {
// properties
// methods
// initializers
}
class Student: NSObject { // no need to derive a class with base as NSObject
}
We can create a subclass and inherited
class Medical: Student {
}
Presenter: Waseem Ahmad, Mindfire Solutions
Properties
class Student {
var rollNo = 1
var name: String?
// methods
// initializers
}
The big difference between objective c and swift is “no difference between Instance
variable and priorities”.
Here rollNo we can say as stored properties.
Presenter: Waseem Ahmad, Mindfire Solutions
Computed Properties
class Student {
var rollNo = 1
var name: String?
var description: String {
get {
return “Hi this (name!) and my roll number is (rollNo)“
}
}
}
Presenter: Waseem Ahmad, Mindfire Solutions
Computed Properties (RW)
class Student {
var rollNo = 1
var name: String?
var description: String {
get {
return “Hi this (name!) and my roll number is (rollNo)“
}
set {
}
}
}
Presenter: Waseem Ahmad, Mindfire Solutions
Computed Properties (Read)
class Student {
var rollNo = 1
var name: String?
var description: String {
return “Hi this (name!) and my roll number is (rollNo)“
}
}
Presenter: Waseem Ahmad, Mindfire Solutions
Initializer Class Syntax
class Student {
var rollNo = 1
var name: String?
var description: String {
return “Hi this (name!) and my roll number is (rollNo)“
}
}
let studentObj = Student()
println(studentObj.description)
- Automatic memory allocation
-No need to write type as Swift support Type Inference
let studentObj : Student = Student()
Presenter: Waseem Ahmad, Mindfire Solutions
Initializer Class Syntax
class Student {
var rollNo = 1
var name: String?
init() { // constructor
string = “Waseem”
}
var description: String {
return “Hi this (name!) and my roll number is (rollNo)“
}
}
Presenter: Waseem Ahmad, Mindfire Solutions
Overriding a Property
class Medical: Student {
init() {
super.init()
}
override var description: String { // Safe
return super.description + ", student of Medical"
}
}
Presenter: Waseem Ahmad, Mindfire Solutions
Property Observers
class Loan: Bank {
override var intrest: Double {
willSet {
// newValue is available here
if intrest > 10.0 {
// calculate // trigger
}
}
}
didSet {
// oldValue is available here
}
}
}
Presenter: Waseem Ahmad, Mindfire Solutions
Methods
class Student {
var rollNo = 1
var name: String?
func studentName(nameStr: String) {
name = nameStr
}
}
Presenter: Waseem Ahmad, Mindfire Solutions
Class Methods
class func isFileExistAtPath(filePath: NSString) -> Bool {
let filemanager = NSFileManager.defaultManager()
return filemanager.fileExistsAtPath(filePath)
}
Presenter: Waseem Ahmad, Mindfire Solutions
Class De-initialisation
class Student {
var rollNo = 1
var name: String?
init() { // constructor
fileOpen() //
}
deinit { // constructor
closeFile() //
}
}
Presenter: Waseem Ahmad, Mindfire Solutions
iPhone App to Advertise
Real Estate
Case Study
www.mindfiresolutions.com
Next Seminar: Swift in depth
Closures
Structures
Enum
Extensions
Memory Management
Optional Chaining
Generic type
Presenter: Waseem Ahmad, Mindfire Solutions
References
- Apple WWDC 2014
- Apple Inc. “The Swift Programming Language.” iBooks.
Presenter: Waseem Ahmad, Mindfire Solutions
Presenter: Waseem Ahmad, Mindfire Solutions
Question and Answer
Thank you
Presenter: Waseem Ahmad, Mindfire Solutions
Ad

More Related Content

Similar to Swift-Programming Part 1 (20)

NUS iOS Swift Talk
NUS iOS Swift TalkNUS iOS Swift Talk
NUS iOS Swift Talk
Gabriel Lim
 
Terraform at Scale
Terraform at ScaleTerraform at Scale
Terraform at Scale
Calvin French-Owen
 
An Introduction to Scala (2014)
An Introduction to Scala (2014)An Introduction to Scala (2014)
An Introduction to Scala (2014)
William Narmontas
 
Intro toswift1
Intro toswift1Intro toswift1
Intro toswift1
Jordan Morgan
 
Python basic
Python basicPython basic
Python basic
Mayur Mohite
 
Why Scala is the better Java
Why Scala is the better JavaWhy Scala is the better Java
Why Scala is the better Java
Thomas Kaiser
 
Exploring Koltin on Android
Exploring Koltin on AndroidExploring Koltin on Android
Exploring Koltin on Android
Deepanshu Madan
 
Kotlin: maybe it's the right time
Kotlin: maybe it's the right timeKotlin: maybe it's the right time
Kotlin: maybe it's the right time
Davide Cerbo
 
Javascript 101
Javascript 101Javascript 101
Javascript 101
Shlomi Komemi
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
None
 
Web app development_php_04
Web app development_php_04Web app development_php_04
Web app development_php_04
Hassen Poreya
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
Bui Kiet
 
Introduction to TypeScript
Introduction to TypeScriptIntroduction to TypeScript
Introduction to TypeScript
Tomas Corral Casas
 
Design Patterns the Ruby way - ConFoo 2015
Design Patterns the Ruby way - ConFoo 2015Design Patterns the Ruby way - ConFoo 2015
Design Patterns the Ruby way - ConFoo 2015
Fred Heath
 
InterConnect: Server Side Swift for Java Developers
InterConnect:  Server Side Swift for Java DevelopersInterConnect:  Server Side Swift for Java Developers
InterConnect: Server Side Swift for Java Developers
Chris Bailey
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Aleksandar Prokopec
 
unity-clinic2-unityscript-basics
unity-clinic2-unityscript-basicsunity-clinic2-unityscript-basics
unity-clinic2-unityscript-basics
Darren Woodiwiss
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
Manvendra Singh
 
Getting the most out of Java [Nordic Coding-2010]
Getting the most out of Java [Nordic Coding-2010]Getting the most out of Java [Nordic Coding-2010]
Getting the most out of Java [Nordic Coding-2010]
Sven Efftinge
 
Polyglot Adventures for the Modern Java Developer #javaone2017
Polyglot Adventures for the Modern Java Developer #javaone2017Polyglot Adventures for the Modern Java Developer #javaone2017
Polyglot Adventures for the Modern Java Developer #javaone2017
Mario-Leander Reimer
 
NUS iOS Swift Talk
NUS iOS Swift TalkNUS iOS Swift Talk
NUS iOS Swift Talk
Gabriel Lim
 
An Introduction to Scala (2014)
An Introduction to Scala (2014)An Introduction to Scala (2014)
An Introduction to Scala (2014)
William Narmontas
 
Why Scala is the better Java
Why Scala is the better JavaWhy Scala is the better Java
Why Scala is the better Java
Thomas Kaiser
 
Exploring Koltin on Android
Exploring Koltin on AndroidExploring Koltin on Android
Exploring Koltin on Android
Deepanshu Madan
 
Kotlin: maybe it's the right time
Kotlin: maybe it's the right timeKotlin: maybe it's the right time
Kotlin: maybe it's the right time
Davide Cerbo
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
None
 
Web app development_php_04
Web app development_php_04Web app development_php_04
Web app development_php_04
Hassen Poreya
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
Bui Kiet
 
Design Patterns the Ruby way - ConFoo 2015
Design Patterns the Ruby way - ConFoo 2015Design Patterns the Ruby way - ConFoo 2015
Design Patterns the Ruby way - ConFoo 2015
Fred Heath
 
InterConnect: Server Side Swift for Java Developers
InterConnect:  Server Side Swift for Java DevelopersInterConnect:  Server Side Swift for Java Developers
InterConnect: Server Side Swift for Java Developers
Chris Bailey
 
unity-clinic2-unityscript-basics
unity-clinic2-unityscript-basicsunity-clinic2-unityscript-basics
unity-clinic2-unityscript-basics
Darren Woodiwiss
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
Manvendra Singh
 
Getting the most out of Java [Nordic Coding-2010]
Getting the most out of Java [Nordic Coding-2010]Getting the most out of Java [Nordic Coding-2010]
Getting the most out of Java [Nordic Coding-2010]
Sven Efftinge
 
Polyglot Adventures for the Modern Java Developer #javaone2017
Polyglot Adventures for the Modern Java Developer #javaone2017Polyglot Adventures for the Modern Java Developer #javaone2017
Polyglot Adventures for the Modern Java Developer #javaone2017
Mario-Leander Reimer
 

More from Mindfire Solutions (20)

Physician Search and Review
Physician Search and ReviewPhysician Search and Review
Physician Search and Review
Mindfire Solutions
 
diet management app
diet management appdiet management app
diet management app
Mindfire Solutions
 
Business Technology Solution
Business Technology SolutionBusiness Technology Solution
Business Technology Solution
Mindfire Solutions
 
Remote Health Monitoring
Remote Health MonitoringRemote Health Monitoring
Remote Health Monitoring
Mindfire Solutions
 
Influencer Marketing Solution
Influencer Marketing SolutionInfluencer Marketing Solution
Influencer Marketing Solution
Mindfire Solutions
 
ELMAH
ELMAHELMAH
ELMAH
Mindfire Solutions
 
High Availability of Azure Applications
High Availability of Azure ApplicationsHigh Availability of Azure Applications
High Availability of Azure Applications
Mindfire Solutions
 
IOT Hands On
IOT Hands OnIOT Hands On
IOT Hands On
Mindfire Solutions
 
Glimpse of Loops Vs Set
Glimpse of Loops Vs SetGlimpse of Loops Vs Set
Glimpse of Loops Vs Set
Mindfire Solutions
 
Oracle Sql Developer-Getting Started
Oracle Sql Developer-Getting StartedOracle Sql Developer-Getting Started
Oracle Sql Developer-Getting Started
Mindfire Solutions
 
Adaptive Layout In iOS 8
Adaptive Layout In iOS 8Adaptive Layout In iOS 8
Adaptive Layout In iOS 8
Mindfire Solutions
 
Introduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/MacIntroduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/Mac
Mindfire Solutions
 
LINQPad - utility Tool
LINQPad - utility ToolLINQPad - utility Tool
LINQPad - utility Tool
Mindfire Solutions
 
Get started with watch kit development
Get started with watch kit developmentGet started with watch kit development
Get started with watch kit development
Mindfire Solutions
 
Swift vs Objective-C
Swift vs Objective-CSwift vs Objective-C
Swift vs Objective-C
Mindfire Solutions
 
Material Design in Android
Material Design in AndroidMaterial Design in Android
Material Design in Android
Mindfire Solutions
 
Introduction to OData
Introduction to ODataIntroduction to OData
Introduction to OData
Mindfire Solutions
 
Ext js Part 2- MVC
Ext js Part 2- MVCExt js Part 2- MVC
Ext js Part 2- MVC
Mindfire Solutions
 
ExtJs Basic Part-1
ExtJs Basic Part-1ExtJs Basic Part-1
ExtJs Basic Part-1
Mindfire Solutions
 
Spring Security Introduction
Spring Security IntroductionSpring Security Introduction
Spring Security Introduction
Mindfire Solutions
 
Ad

Recently uploaded (20)

PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
Top 10 Data Cleansing Tools for 2025.pdf
Top 10 Data Cleansing Tools for 2025.pdfTop 10 Data Cleansing Tools for 2025.pdf
Top 10 Data Cleansing Tools for 2025.pdf
AffinityCore
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Apple Logic Pro X Crack FRESH Version 2025
Apple Logic Pro X Crack FRESH Version 2025Apple Logic Pro X Crack FRESH Version 2025
Apple Logic Pro X Crack FRESH Version 2025
fs4635986
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Odoo ERP for Education Management to Streamline Your Education Process
Odoo ERP for Education Management to Streamline Your Education ProcessOdoo ERP for Education Management to Streamline Your Education Process
Odoo ERP for Education Management to Streamline Your Education Process
iVenture Team LLP
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
Top 10 Data Cleansing Tools for 2025.pdf
Top 10 Data Cleansing Tools for 2025.pdfTop 10 Data Cleansing Tools for 2025.pdf
Top 10 Data Cleansing Tools for 2025.pdf
AffinityCore
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Apple Logic Pro X Crack FRESH Version 2025
Apple Logic Pro X Crack FRESH Version 2025Apple Logic Pro X Crack FRESH Version 2025
Apple Logic Pro X Crack FRESH Version 2025
fs4635986
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Odoo ERP for Education Management to Streamline Your Education Process
Odoo ERP for Education Management to Streamline Your Education ProcessOdoo ERP for Education Management to Streamline Your Education Process
Odoo ERP for Education Management to Streamline Your Education Process
iVenture Team LLP
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
Ad

Swift-Programming Part 1

  • 1. 1 Introduction of Swift Presenter: Waseem Ahmad, Mindfire Solutions Date: 28/10/2014
  • 2. What you will learn Presenter: Waseem Ahmad, Mindfire Solutions What is Swift? Variable Constants Type Inference Type Aliases String/Character Interpolation Array and Dictionary Loops Optionals, Unwrapping an Optional Functions Tuples Classes Properties Closures Q & A
  • 3. What is Swift ? • Swift is Apple’s modern, type-safe language for Cocoa development that builds on the best of C and Objective-C • Safe • Modern • Power Presenter: Waseem Ahmad, Mindfire Solutions
  • 4. Variables var variableName : String = “Swift” var version: Double = 1.0 var day: Int = 28 var isAnimated: Bool = true Presenter: Waseem Ahmad, Mindfire Solutions
  • 5. Constants &Variables let variableName: String = “Swift” var version: Double = 1.0 var day: Int = 28 var isAnimated: Bool = true Pretty clear which is constant and mutable, it’s define safe code in multithreaded environment. Make code more clear and readable. Presenter: Waseem Ahmad, Mindfire Solutions
  • 6. Constants &Variables let variableName: String = “Swift” var version: Double = 1.0 let day: Int = 28 let isAnimated: Bool = true Presenter: Waseem Ahmad, Mindfire Solutions
  • 7. Type Inference let variableName = “Swift” // As String var version = 1.0 // As Double/Float let day = 28 // As Int let isAnimated = true // As Boolean Code safe, these are valuable & constant explicitly type. Presenter: Waseem Ahmad, Mindfire Solutions
  • 8. Type Aliases An alternative name for an existing type. typealias AudioSample = UInt16 var maxAmplitudeFound = AudioSample.min Presenter: Waseem Ahmad, Mindfire Solutions
  • 9. Unicode Names let variableName = “Swift” // As String var version = 1.0 // As Double/Float let day = 28 // As Int let isAnimated = true // As Boolean let π = 3.1415927 let � = "emoji"� Presenter: Waseem Ahmad, Mindfire Solutions
  • 10. String var studentName: String = “Waseem” var studentName = “Waseem” // Inferred to be of type string Presenter: Waseem Ahmad, Mindfire Solutions
  • 11. String var studentName: String = “Waseem” var studentName = “Waseem” // Inferred to be of type string var documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String documentsPath = documentsPath.stringByAppendingString(subpath) Presenter: Waseem Ahmad, Mindfire Solutions
  • 12. Character let studentName = “Waseem" for character in studentName { println(character) } W a s e e m Presenter: Waseem Ahmad, Mindfire Solutions
  • 13. Complex String var name = “Waseem” var coins = 100 Congratulations, Waseem won 100 coins. Presenter: Waseem Ahmad, Mindfire Solutions
  • 14. String Interpolation var name = “Waseem” var coins = 100 Congratulations, Waseem won 100 coins. let message = “Congratulations, (name) won (coins)”. Presenter: Waseem Ahmad, Mindfire Solutions
  • 15. String Mutability var variableString = "Mindfire" Presenter: Waseem Ahmad, Mindfire Solutions
  • 16. String Mutability var variableString = “Mindfire" variableString += " Solutions” // variableString is now “Mindfire Solutions" Presenter: Waseem Ahmad, Mindfire Solutions
  • 17. String Mutability var variableString = “Mindfire" variableString += " Solutions” // variableString is now “Mindfire Solutions" let constantString = “Mindfire" constantString += " Solutions” // error - constantString cannot be changed Presenter: Waseem Ahmad, Mindfire Solutions
  • 18. String Mutability var variableString = “Mindfire" variableString += " Solutions” // variableString is now “Mindfire Solutions" let constantString = “Mindfire" constantString += " Solutions” // error - constantString cannot be changed Presenter: Waseem Ahmad, Mindfire Solutions
  • 19. Collection Type (Array & Dictionary) Presenter: Waseem Ahmad, Mindfire Solutions
  • 20. Array and Dictionary Literals var names = [“John”, “Bob”, "Brian", "Jack"] Presenter: Waseem Ahmad, Mindfire Solutions
  • 21. Array and Dictionary Literals var names = [“John”, “Bob”, "Brian", “Jack"] var numberOfLegs = ["ant": 6, "snake": 0, "cheetah": 4] Presenter: Waseem Ahmad, Mindfire Solutions
  • 22. Difference Between NSArray & NSDictionary - It could work with any type (String, Int etc) - Collection are typed collection Presenter: Waseem Ahmad, Mindfire Solutions
  • 23. Typed Collection var names = [“John”, “Bob”, "Brian", “Jack”, 123] var names = [“John”, “Bob”, "Brian", “Jack”, function()] Presenter: Waseem Ahmad, Mindfire Solutions
  • 24. Typed Collection var names: String[] = [“John”, “Bob”, "Brian", “Jack”] Presenter: Waseem Ahmad, Mindfire Solutions
  • 25. Typed Collection var names = [“John”, “Bob”, "Brian", “Jack”] // An array of String Values var numberOfLegs = ["ant": 6, "snake": 0, "cheetah": 4] // An Dictionary With String Keys and Int Values Typed collection made your code safe, you well know what you are retrieving and adding. Presenter: Waseem Ahmad, Mindfire Solutions
  • 26. Loop while !isTrue { print(“hello”) } for var i = 1; i <= 13; ++i { print(“hello”) } Presenter: Waseem Ahmad, Mindfire Solutions
  • 27. For-In: Strings and Characters let studentName = “Waseem" for character in studentName { println(character) } W a s e e m Swift Power, we can use character & emoji in similar way. Presenter: Waseem Ahmad, Mindfire Solutions
  • 28. For-In: Ranges for number in 1...5 { // Clause Range println("(number) times 4 is (number * 4)") } 1 times 4 is 4 2 times 4 is 8 3 times 4 is 12 4 times 4 is 16 5 times 4 is 20 Presenter: Waseem Ahmad, Mindfire Solutions
  • 29. For-In: Ranges for number in 0..5 { // half clause range println("(number) times 4 is (number * 4)") } 0 times 4 is 0 1 times 4 is 4 2 times 4 is 8 3 times 4 is 12 4 times 4 is 16 Presenter: Waseem Ahmad, Mindfire Solutions
  • 30. For-In: Array var names = [“John”, “Bob”, "Brian", "Jack"] for name in names { println("Hello (name)") } Presenter: Waseem Ahmad, Mindfire Solutions
  • 31. For-In: Dictionaries let numberOfLegs = ["ant": 6, "snake": 0, "cheetah": 4] ! for (animalName, legCount) in numberOfLegs { println("(animalName)s have (legCount) legs") } ants have 6 legs Power of swift extracting key and value in single loop, grouping of value is a power full feature of swift i.e Tuples Presenter: Waseem Ahmad, Mindfire Solutions
  • 32. Modification in Array var shoppingList = ["Eggs", "Milk"] println(shoppingList[0]) Presenter: Waseem Ahmad, Mindfire Solutions
  • 33. Modification in Array var shoppingList = ["Eggs", "Milk"] println(shoppingList[0]) shoppingList += "Flour" shoppingList += ["Cheese", "Butter", "Chocolate Spread"] Presenter: Waseem Ahmad, Mindfire Solutions
  • 34. Modification in Array var shoppingList = ["Eggs", "Milk"] shoppingList += "Flour" shoppingList += ["Cheese", "Butter", "Chocolate Spread”] shoppingList[0] = "Six eggs" Presenter: Waseem Ahmad, Mindfire Solutions
  • 35. Modification in Array var shoppingList = ["Eggs", "Milk"] shoppingList += "Flour" shoppingList += ["Cheese", "Butter", "Chocolate Spread”] shoppingList[0] = "Six eggs” ["Six eggs", "Milk", "Flour", "Cheese", "Butter", "Chocolate Spread"] shoppingList[3...5] = ["Bananas", “Apples"] ["Six eggs", "Milk", "Flour", "Bananas", “Apples"] Presenter: Waseem Ahmad, Mindfire Solutions
  • 36. Modification in Dictionary var numberOfLegs = ["ant": 6, "snake": 0, "cheetah": 4] numberOfLegs["spider"] = 273 Presenter: Waseem Ahmad, Mindfire Solutions
  • 37. Modification in Dictionary var numberOfLegs = ["ant": 6, "snake": 0, "cheetah": 4] numberOfLegs["spider"] = 273 numberOfLegs["spider"] = 8 What happen if we try to fetch a value that doesn’t have in array and dictionary? let lionLegCount = numberOfLegs[“lion”] // Nothing at all :) Presenter: Waseem Ahmad, Mindfire Solutions
  • 38. Optional var numberOfLegs = ["ant": 6, "snake": 0, "cheetah": 4] let lionLegCount: Int? = numberOfLegs["lion"] Presenter: Waseem Ahmad, Mindfire Solutions
  • 39. Optional var numberOfLegs = ["ant": 6, "snake": 0, "cheetah": 4] let lionLegCount: Int? = numberOfLegs[“lion"] if lionLegCount == nil { println("Lion wasn't found") } else { let legCount = lionLegCount! // unwrapping of optional value println("An lion has (legCount) legs") } Presenter: Waseem Ahmad, Mindfire Solutions
  • 40. Optional if numberOfLegs { let legCount = numberOfLegs! println("An Lion has (legCount) legs") } Presenter: Waseem Ahmad, Mindfire Solutions
  • 41. Unwrapping an Optional if let legCount = numberOfLegs { println("An Lion has (legCount) legs") } Note:- Braces are required with If :) Presenter: Waseem Ahmad, Mindfire Solutions
  • 42. Switch switch legCount { case 0: println("It slithers and slides around”) case 1: println("It hops") default: println("It walks") } Presenter: Waseem Ahmad, Mindfire Solutions
  • 43. Switch switch sender { case executeButton: println("You tapped the Execute button") case firstNameTextField: println("You tapped the First Name text field") default: println("You tapped some other object") } Presenter: Waseem Ahmad, Mindfire Solutions
  • 44. Switch switch legCount { case 0: println("It slithers and slides around")! case 1, 3, 5, 7, 9, 11, 13: println("It limps") case 2, 4, 6, 8, 10, 12, 14: println("It walks") } // error: switch must be exhaustive Presenter: Waseem Ahmad, Mindfire Solutions
  • 45. Switch switch legCount { case 0: println("It slithers and slides around")! case 1, 3, 5, 7, 9, 11, 13: println("It limps") case 2, 4, 6, 8, 10, 12, 14: println("It walks”) default: println("It walks") } Presenter: Waseem Ahmad, Mindfire Solutions
  • 46. Matching Value Ranges switch legCount { case 0: println("It slithers and slides around")! case 1…8: println("It has few lags") default: println("It walks") } Presenter: Waseem Ahmad, Mindfire Solutions
  • 48. Functions with Parameters func sayHello(name: String) { println("Hello (name)!") } Presenter: Waseem Ahmad, Mindfire Solutions
  • 49. Default Parameter Values func sayHello(name: String = "World") { println("Hello (name)!") } sayHello() // Hello World sayHello(“Team”) // Hello Team Presenter: Waseem Ahmad, Mindfire Solutions
  • 50. Returning Values func greetingMsg(name: String = "World") -> String { return "Hello " + name } let greeting = greetingMsg() Presenter: Waseem Ahmad, Mindfire Solutions
  • 51. Returning Multiple Values func getUsernInfo() -> (Int, String) { return (25, “John”) } Presenter: Waseem Ahmad, Mindfire Solutions
  • 52. Tuples -Grouping a values -Value could be any type (3.79, 3.99, 4.19) // (Double, Double, Double) (404, "Not found") (2, "banana", 0.72) -Tuple is not an replacement of structure but this is best when needs to return multiple values like from function func getUsernInfo() -> (Int, String) { return (25, “John”) } Presenter: Waseem Ahmad, Mindfire Solutions
  • 53. Decomposing of Tuples func getUsernInfo() -> (Int, String) { return (25, “John”) } let (age, name) = getUsernInfo() println(“This is (name) and my age is (age)") Presenter: Waseem Ahmad, Mindfire Solutions
  • 54. Decomposing of Tuples func getUsernInfo() -> (Int, String) { return (25, “John”) } let (age, name) = getUsernInfo() let (age: Int, name: String) = getUsernInfo() println(“This is (name) and my age is (age)") If you only need some of the tuple’s values, ignore parts of the tuple with an underscore (_) when you decompose the tuple: let (age, _) = getUsernInfo() Presenter: Waseem Ahmad, Mindfire Solutions
  • 55. Named Values in a Tuple func getUsernInfo() -> (age: Int, name: String) { return (25, “John”) } let userInfo = getUsernInfo() println(“This is (userInfo.name) and my age is (userInfo.age)”) Presenter: Waseem Ahmad, Mindfire Solutions
  • 56. Classes class Student { // properties // methods // initializers } class Student: NSObject { // no need to derive a class with base as NSObject } We can create a subclass and inherited class Medical: Student { } Presenter: Waseem Ahmad, Mindfire Solutions
  • 57. Properties class Student { var rollNo = 1 var name: String? // methods // initializers } The big difference between objective c and swift is “no difference between Instance variable and priorities”. Here rollNo we can say as stored properties. Presenter: Waseem Ahmad, Mindfire Solutions
  • 58. Computed Properties class Student { var rollNo = 1 var name: String? var description: String { get { return “Hi this (name!) and my roll number is (rollNo)“ } } } Presenter: Waseem Ahmad, Mindfire Solutions
  • 59. Computed Properties (RW) class Student { var rollNo = 1 var name: String? var description: String { get { return “Hi this (name!) and my roll number is (rollNo)“ } set { } } } Presenter: Waseem Ahmad, Mindfire Solutions
  • 60. Computed Properties (Read) class Student { var rollNo = 1 var name: String? var description: String { return “Hi this (name!) and my roll number is (rollNo)“ } } Presenter: Waseem Ahmad, Mindfire Solutions
  • 61. Initializer Class Syntax class Student { var rollNo = 1 var name: String? var description: String { return “Hi this (name!) and my roll number is (rollNo)“ } } let studentObj = Student() println(studentObj.description) - Automatic memory allocation -No need to write type as Swift support Type Inference let studentObj : Student = Student() Presenter: Waseem Ahmad, Mindfire Solutions
  • 62. Initializer Class Syntax class Student { var rollNo = 1 var name: String? init() { // constructor string = “Waseem” } var description: String { return “Hi this (name!) and my roll number is (rollNo)“ } } Presenter: Waseem Ahmad, Mindfire Solutions
  • 63. Overriding a Property class Medical: Student { init() { super.init() } override var description: String { // Safe return super.description + ", student of Medical" } } Presenter: Waseem Ahmad, Mindfire Solutions
  • 64. Property Observers class Loan: Bank { override var intrest: Double { willSet { // newValue is available here if intrest > 10.0 { // calculate // trigger } } } didSet { // oldValue is available here } } } Presenter: Waseem Ahmad, Mindfire Solutions
  • 65. Methods class Student { var rollNo = 1 var name: String? func studentName(nameStr: String) { name = nameStr } } Presenter: Waseem Ahmad, Mindfire Solutions
  • 66. Class Methods class func isFileExistAtPath(filePath: NSString) -> Bool { let filemanager = NSFileManager.defaultManager() return filemanager.fileExistsAtPath(filePath) } Presenter: Waseem Ahmad, Mindfire Solutions
  • 67. Class De-initialisation class Student { var rollNo = 1 var name: String? init() { // constructor fileOpen() // } deinit { // constructor closeFile() // } } Presenter: Waseem Ahmad, Mindfire Solutions
  • 68. iPhone App to Advertise Real Estate Case Study www.mindfiresolutions.com
  • 69. Next Seminar: Swift in depth Closures Structures Enum Extensions Memory Management Optional Chaining Generic type Presenter: Waseem Ahmad, Mindfire Solutions
  • 70. References - Apple WWDC 2014 - Apple Inc. “The Swift Programming Language.” iBooks. Presenter: Waseem Ahmad, Mindfire Solutions
  • 71. Presenter: Waseem Ahmad, Mindfire Solutions Question and Answer
  • 72. Thank you Presenter: Waseem Ahmad, Mindfire Solutions