SlideShare a Scribd company logo
1 of 42
Download to read offline
SWIFT THE implicit PARTS
MAXIM ZAKS 
@ICEX33
WHAT DO I MEAN BY implicit PARTS?
AGENDA 
▸ Values 
▸ Functions 
▸ Structures
Declaration of a constant 
let name : String = "Maxim";
Declaration of a constant with type inference and without semicolon 
let name = "Maxim"
Declaration of constant immutable array 
let names : Array<String> = ["Maxim", "Anton"] 
let names : [String] = ["Maxim", "Anton"] 
let names = ["Maxim", "Anton"] 
names.append("Fox") // Compile error
Declaration of mutable array (as variable) 
var names = ["Maxim", "Anton"] 
names.append("Fox") // ["Maxim", "Anton", "Fox"]
Declaration of Optional value 
var name : Optional<String> = "Maxim" 
name!.isEmpty == false // ??? 
var name : String? = nil 
name?.isEmpty == false // ???
Declaration of unwraped value if applicable 
var name : String? = nil 
if let _name = name { 
print("(_name)") 
} else { 
print("No name!") 
}
Declaration of value which is only optional in the beginning 
var name : ImplicitlyUnwrappedOptional<String> = "Maxim" 
name.isEmpty 
var name : String! = nil 
name.isEmpty // Runtime Exception
Decomposition of touples 
var a = 0, b = 0 
let touple = (20, 30) 
a = touple.0 
b = touple.1 
// Or just like this: 
(a, b) = touple
Convert from literal 
let url : NSURL = "http://nshipster.com/" 
"http://nshipster.com/".host
extension NSURL: StringLiteralConvertible { 
public class func convertFromExtendedGraphemeClusterLiteral(value: String) -> Self { 
return self(string: value) 
} 
public class func convertFromStringLiteral(value: String) -> Self { 
return self(string: value) 
} 
}
▸ NilLiteralConvertible 
▸ BooleanLiteralConvertible 
▸ IntegerLiteralConvertible 
▸ FloatLiteralConvertible 
▸ StringLiteralConvertible / UnicodeScalarLiteralConvertible / 
ExtendedGraphemeClusterLiteralConvertible 
▸ ArrayLiteralConvertible 
▸ DictionaryLiteralConvertible
FUNCTIONS
Shortes function 
func f() -> Void {} 
func f() -> () {} 
func f() {}
Function without parameter label 
func f(_ v : Int) -> Int { return v + 1 } 
func f(v : Int) -> Int { return v + 1 } 
let v1 = f(10) // v1 = 11
Functoin with parameter label equal to parameter name 
func f(value value : Int) -> Int { return value + 1 } 
func f(#value : Int) -> Int { return value + 1 } 
let v1 = f(value : 10) // v1 = 11
In/Out parameter 
func f(inout v : Int) { v + 1 } 
var v = 10 
f(&v) // v = 11
Copy parameter in to variable 
func f(var v : [String]) -> [String] { 
v.append("Anton") 
return v 
} 
let a = ["Maxim"] 
let a2 = f(a) // a = ["Maxim"] , a2 = ["Maxim", "Anton"]
Rest parameter 
func sum(values:Int...) -> Int{ 
return values.reduce(0, +) 
} 
let sum1 = sum(1,2,3,4) // sum1 = 10 
let sum2 = sum() // sum2 = 0
Default parameter value 
func f(_ v : Int = 10) -> Int { 
return v + 1 
} 
let v1 = f() // v1 = 11 
let v2 = f(3) // v2 = 4
Curried function 
func f(a : Int)(b : Int) -> Int { 
return a + b 
} 
let v1 = f(1)(2)
Returning a closure (idea behind currying) 
func f(a : Int) -> (Int -> Int) { 
let f1 = { 
(b: Int) -> Int in 
return a + b 
} 
return f1 
} 
let v1 = f(1)(2)
Returning a closure (idea behind currying) 
func f(a : Int) -> (Int -> Int) { 
return { 
(b: Int) -> Int in 
return a + b 
} 
} 
let v1 = f(1)(2)
Remove Closure types 
func f(a : Int) -> (Int -> Int) { 
return { 
b in 
return a + b 
} 
} 
let v1 = f(1)(2)
Remove return keyword 
func f(a : Int) -> (Int -> Int) { 
return { 
b in a + b 
} 
} 
let v1 = f(1)(2)
Remove parameter name 
func f(a : Int) -> (Int -> Int) { 
return { 
a + $0 
} 
} 
let v1 = f(1)(2)
Call a function with value 
func f(sum : Int) { 
print("sum is (sum)") 
} 
f(1 + 2) // f(3)
Call function with closure enables lazy evaluation 
func f(sum : () -> Int) { 
print("sum is (sum())") 
} 
f({1 + 2}) // lazy evaluation
Call function with auto closure enables lazy evaluation implicitly 
func f(sum : @autoclosure () -> Int) { 
print("sum is (sum())") 
} 
f(1 + 2) // still lazy evaluation
If last operator is a function you can take it out of parenthesis 
func f(a : Int, b: Int, operation : (Int,Int) -> Int) { 
print("sum is ( operation(a, b) )") 
} 
f(1,2) { 
$0 + $1 
}
Or keep it 
func f(a : Int, b: Int, operation : (Int,Int) -> Int) { 
print("sum is ( operation(a, b) )") 
} 
f(1, 2, +)
Operators are functions 
1 + 2 
infix operator + { 
associativity left 
precedence 140 
} 
func +(lhs: Int, rhs: Int) -> Int
Execution is based on precedence 
1 + 2 * 4 
infix operator + { 
associativity left 
precedence 140 
} 
infix operator * { 
associativity left 
precedence 150 
}
STRUCTURES
Touple with named values can be used as structs 
typealias MyPoint = (x:Int, y:Int) 
let point : MyPoint = (x:25, y:30) 
point.x // 25 
point.y // 30
Struct with implicit intializer 
struct MyPoint { 
let x : Int 
let y : Int 
} 
let point = MyPoint(x:25, y:30) 
point.x // 25 
point.y // 30
Methods are curried functions 
struct MyName { 
let name : String 
init(_ n : String) { 
name = n 
} 
func desc()->String{ 
return "My name is: (name)" 
} 
} 
let myName = MyName("Maxim") 
myName.desc() 
MyName.desc(myName)()
TO BE 
CONTINUED...
THANK YOU! @ICEX33

More Related Content

What's hot

The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84Mahmoud Samir Fayed
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacksmaamir farooq
 
Abstracting over Execution with Higher Kinded Types
Abstracting over Execution with Higher Kinded TypesAbstracting over Execution with Higher Kinded Types
Abstracting over Execution with Higher Kinded TypesPhilip Schwarz
 
Functions in python
Functions in pythonFunctions in python
Functions in pythonIlian Iliev
 
The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 11 of 84
The Ring programming language version 1.2 book - Part 11 of 84The Ring programming language version 1.2 book - Part 11 of 84
The Ring programming language version 1.2 book - Part 11 of 84Mahmoud Samir Fayed
 
Atomically { Delete Your Actors }
Atomically { Delete Your Actors }Atomically { Delete Your Actors }
Atomically { Delete Your Actors }John De Goes
 
The Ring programming language version 1.2 book - Part 9 of 84
The Ring programming language version 1.2 book - Part 9 of 84The Ring programming language version 1.2 book - Part 9 of 84
The Ring programming language version 1.2 book - Part 9 of 84Mahmoud Samir Fayed
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meetMario Fusco
 
Functional programming in Python
Functional programming in PythonFunctional programming in Python
Functional programming in PythonColin Su
 
Functors, applicatives, monads
Functors, applicatives, monadsFunctors, applicatives, monads
Functors, applicatives, monadsrkaippully
 
C tech questions
C tech questionsC tech questions
C tech questionsvijay00791
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklistritu1806
 
Fp in scala with adts part 2
Fp in scala with adts part 2Fp in scala with adts part 2
Fp in scala with adts part 2Hang Zhao
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2Amit Kapoor
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...ssuserd6b1fd
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2vikram mahendra
 
Fp in scala with adts
Fp in scala with adtsFp in scala with adts
Fp in scala with adtsHang Zhao
 

What's hot (20)

The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
 
Abstracting over Execution with Higher Kinded Types
Abstracting over Execution with Higher Kinded TypesAbstracting over Execution with Higher Kinded Types
Abstracting over Execution with Higher Kinded Types
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84
 
The Ring programming language version 1.2 book - Part 11 of 84
The Ring programming language version 1.2 book - Part 11 of 84The Ring programming language version 1.2 book - Part 11 of 84
The Ring programming language version 1.2 book - Part 11 of 84
 
Atomically { Delete Your Actors }
Atomically { Delete Your Actors }Atomically { Delete Your Actors }
Atomically { Delete Your Actors }
 
The Ring programming language version 1.2 book - Part 9 of 84
The Ring programming language version 1.2 book - Part 9 of 84The Ring programming language version 1.2 book - Part 9 of 84
The Ring programming language version 1.2 book - Part 9 of 84
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
 
Functional programming in Python
Functional programming in PythonFunctional programming in Python
Functional programming in Python
 
Functors, applicatives, monads
Functors, applicatives, monadsFunctors, applicatives, monads
Functors, applicatives, monads
 
C tech questions
C tech questionsC tech questions
C tech questions
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
 
Haskell 101
Haskell 101Haskell 101
Haskell 101
 
Fp in scala with adts part 2
Fp in scala with adts part 2Fp in scala with adts part 2
Fp in scala with adts part 2
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
 
USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2USE OF PRINT IN PYTHON PART 2
USE OF PRINT IN PYTHON PART 2
 
Stack, queue and hashing
Stack, queue and hashingStack, queue and hashing
Stack, queue and hashing
 
Fp in scala with adts
Fp in scala with adtsFp in scala with adts
Fp in scala with adts
 

Similar to Swift the implicit parts

TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsEelco Visser
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기진성 오
 
Humble introduction to category theory in haskell
Humble introduction to category theory in haskellHumble introduction to category theory in haskell
Humble introduction to category theory in haskellJongsoo Lee
 
Swift Rocks #2: Going functional
Swift Rocks #2: Going functionalSwift Rocks #2: Going functional
Swift Rocks #2: Going functionalHackraft
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming iiPrashant Kalkar
 
Functions In Scala
Functions In Scala Functions In Scala
Functions In Scala Knoldus Inc.
 
3 kotlin vs. java- what kotlin has that java does not
3  kotlin vs. java- what kotlin has that java does not3  kotlin vs. java- what kotlin has that java does not
3 kotlin vs. java- what kotlin has that java does notSergey Bandysik
 
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)Tomohiro Kumagai
 
Stanfy MadCode Meetup #9: Functional Programming 101 with Swift
Stanfy MadCode Meetup #9: Functional Programming 101 with SwiftStanfy MadCode Meetup #9: Functional Programming 101 with Swift
Stanfy MadCode Meetup #9: Functional Programming 101 with SwiftStanfy
 
All About ... Functions
All About ... FunctionsAll About ... Functions
All About ... FunctionsMichal Bigos
 
Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)Calvin Cheng
 
Composition birds-and-recursion
Composition birds-and-recursionComposition birds-and-recursion
Composition birds-and-recursionDavid Atchley
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchainedEduard Tomàs
 
Why Haskell Matters
Why Haskell MattersWhy Haskell Matters
Why Haskell Mattersromanandreg
 
Generics and Inference
Generics and InferenceGenerics and Inference
Generics and InferenceRichard Fox
 

Similar to Swift the implicit parts (20)

TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class Functions
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
 
Humble introduction to category theory in haskell
Humble introduction to category theory in haskellHumble introduction to category theory in haskell
Humble introduction to category theory in haskell
 
Swift Rocks #2: Going functional
Swift Rocks #2: Going functionalSwift Rocks #2: Going functional
Swift Rocks #2: Going functional
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
 
Functions In Scala
Functions In Scala Functions In Scala
Functions In Scala
 
3 kotlin vs. java- what kotlin has that java does not
3  kotlin vs. java- what kotlin has that java does not3  kotlin vs. java- what kotlin has that java does not
3 kotlin vs. java- what kotlin has that java does not
 
Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)Swift 3.0 の新しい機能(のうちの9つ)
Swift 3.0 の新しい機能(のうちの9つ)
 
Swift study: Closure
Swift study: ClosureSwift study: Closure
Swift study: Closure
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Stanfy MadCode Meetup #9: Functional Programming 101 with Swift
Stanfy MadCode Meetup #9: Functional Programming 101 with SwiftStanfy MadCode Meetup #9: Functional Programming 101 with Swift
Stanfy MadCode Meetup #9: Functional Programming 101 with Swift
 
All About ... Functions
All About ... FunctionsAll About ... Functions
All About ... Functions
 
functions
functionsfunctions
functions
 
C++ lecture 03
C++   lecture 03C++   lecture 03
C++ lecture 03
 
Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)Functional Programming for OO Programmers (part 2)
Functional Programming for OO Programmers (part 2)
 
Composition birds-and-recursion
Composition birds-and-recursionComposition birds-and-recursion
Composition birds-and-recursion
 
10. funtions and closures IN SWIFT PROGRAMMING
10. funtions and closures IN SWIFT PROGRAMMING10. funtions and closures IN SWIFT PROGRAMMING
10. funtions and closures IN SWIFT PROGRAMMING
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchained
 
Why Haskell Matters
Why Haskell MattersWhy Haskell Matters
Why Haskell Matters
 
Generics and Inference
Generics and InferenceGenerics and Inference
Generics and Inference
 

More from Maxim Zaks

Entity Component System - a different approach to game and app development
Entity Component System - a different approach to game and app developmentEntity Component System - a different approach to game and app development
Entity Component System - a different approach to game and app developmentMaxim Zaks
 
Nitty Gritty of Data Serialisation
Nitty Gritty of Data SerialisationNitty Gritty of Data Serialisation
Nitty Gritty of Data SerialisationMaxim Zaks
 
Wind of change
Wind of changeWind of change
Wind of changeMaxim Zaks
 
Data model mal anders
Data model mal andersData model mal anders
Data model mal andersMaxim Zaks
 
Talk Binary to Me
Talk Binary to MeTalk Binary to Me
Talk Binary to MeMaxim Zaks
 
Entity Component System - for App developers
Entity Component System - for App developersEntity Component System - for App developers
Entity Component System - for App developersMaxim Zaks
 
Beyond JSON - An Introduction to FlatBuffers
Beyond JSON - An Introduction to FlatBuffersBeyond JSON - An Introduction to FlatBuffers
Beyond JSON - An Introduction to FlatBuffersMaxim Zaks
 
Beyond JSON @ Mobile.Warsaw
Beyond JSON @ Mobile.WarsawBeyond JSON @ Mobile.Warsaw
Beyond JSON @ Mobile.WarsawMaxim Zaks
 
Beyond JSON @ dot swift 2016
Beyond JSON @ dot swift 2016Beyond JSON @ dot swift 2016
Beyond JSON @ dot swift 2016Maxim Zaks
 
Beyond JSON with FlatBuffers
Beyond JSON with FlatBuffersBeyond JSON with FlatBuffers
Beyond JSON with FlatBuffersMaxim Zaks
 
Basics of Computer Science
Basics of Computer ScienceBasics of Computer Science
Basics of Computer ScienceMaxim Zaks
 
Entity system architecture with Unity @Unite Europe 2015
Entity system architecture with Unity @Unite Europe 2015 Entity system architecture with Unity @Unite Europe 2015
Entity system architecture with Unity @Unite Europe 2015 Maxim Zaks
 
UIKonf App & Data Driven Design @swift.berlin
UIKonf App & Data Driven Design @swift.berlinUIKonf App & Data Driven Design @swift.berlin
UIKonf App & Data Driven Design @swift.berlinMaxim Zaks
 
Currying in Swift
Currying in SwiftCurrying in Swift
Currying in SwiftMaxim Zaks
 
Promise of an API
Promise of an APIPromise of an API
Promise of an APIMaxim Zaks
 
96% macoun 2013
96% macoun 201396% macoun 2013
96% macoun 2013Maxim Zaks
 
Diagnose of Agile @ Wooga 04.2013
Diagnose of Agile @ Wooga 04.2013Diagnose of Agile @ Wooga 04.2013
Diagnose of Agile @ Wooga 04.2013Maxim Zaks
 
Start playing @ mobile.cologne 2013
Start playing @ mobile.cologne 2013Start playing @ mobile.cologne 2013
Start playing @ mobile.cologne 2013Maxim Zaks
 
Under Cocos2D Tree @mdvecon 2013
Under Cocos2D Tree @mdvecon 2013Under Cocos2D Tree @mdvecon 2013
Under Cocos2D Tree @mdvecon 2013Maxim Zaks
 
Don&rsquo;t do Agile, be Agile @NSConf 2013
Don&rsquo;t do Agile, be Agile @NSConf 2013Don&rsquo;t do Agile, be Agile @NSConf 2013
Don&rsquo;t do Agile, be Agile @NSConf 2013Maxim Zaks
 

More from Maxim Zaks (20)

Entity Component System - a different approach to game and app development
Entity Component System - a different approach to game and app developmentEntity Component System - a different approach to game and app development
Entity Component System - a different approach to game and app development
 
Nitty Gritty of Data Serialisation
Nitty Gritty of Data SerialisationNitty Gritty of Data Serialisation
Nitty Gritty of Data Serialisation
 
Wind of change
Wind of changeWind of change
Wind of change
 
Data model mal anders
Data model mal andersData model mal anders
Data model mal anders
 
Talk Binary to Me
Talk Binary to MeTalk Binary to Me
Talk Binary to Me
 
Entity Component System - for App developers
Entity Component System - for App developersEntity Component System - for App developers
Entity Component System - for App developers
 
Beyond JSON - An Introduction to FlatBuffers
Beyond JSON - An Introduction to FlatBuffersBeyond JSON - An Introduction to FlatBuffers
Beyond JSON - An Introduction to FlatBuffers
 
Beyond JSON @ Mobile.Warsaw
Beyond JSON @ Mobile.WarsawBeyond JSON @ Mobile.Warsaw
Beyond JSON @ Mobile.Warsaw
 
Beyond JSON @ dot swift 2016
Beyond JSON @ dot swift 2016Beyond JSON @ dot swift 2016
Beyond JSON @ dot swift 2016
 
Beyond JSON with FlatBuffers
Beyond JSON with FlatBuffersBeyond JSON with FlatBuffers
Beyond JSON with FlatBuffers
 
Basics of Computer Science
Basics of Computer ScienceBasics of Computer Science
Basics of Computer Science
 
Entity system architecture with Unity @Unite Europe 2015
Entity system architecture with Unity @Unite Europe 2015 Entity system architecture with Unity @Unite Europe 2015
Entity system architecture with Unity @Unite Europe 2015
 
UIKonf App & Data Driven Design @swift.berlin
UIKonf App & Data Driven Design @swift.berlinUIKonf App & Data Driven Design @swift.berlin
UIKonf App & Data Driven Design @swift.berlin
 
Currying in Swift
Currying in SwiftCurrying in Swift
Currying in Swift
 
Promise of an API
Promise of an APIPromise of an API
Promise of an API
 
96% macoun 2013
96% macoun 201396% macoun 2013
96% macoun 2013
 
Diagnose of Agile @ Wooga 04.2013
Diagnose of Agile @ Wooga 04.2013Diagnose of Agile @ Wooga 04.2013
Diagnose of Agile @ Wooga 04.2013
 
Start playing @ mobile.cologne 2013
Start playing @ mobile.cologne 2013Start playing @ mobile.cologne 2013
Start playing @ mobile.cologne 2013
 
Under Cocos2D Tree @mdvecon 2013
Under Cocos2D Tree @mdvecon 2013Under Cocos2D Tree @mdvecon 2013
Under Cocos2D Tree @mdvecon 2013
 
Don&rsquo;t do Agile, be Agile @NSConf 2013
Don&rsquo;t do Agile, be Agile @NSConf 2013Don&rsquo;t do Agile, be Agile @NSConf 2013
Don&rsquo;t do Agile, be Agile @NSConf 2013
 

Recently uploaded

On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 

Recently uploaded (20)

On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 

Swift the implicit parts

  • 3. WHAT DO I MEAN BY implicit PARTS?
  • 4. AGENDA ▸ Values ▸ Functions ▸ Structures
  • 5. Declaration of a constant let name : String = "Maxim";
  • 6. Declaration of a constant with type inference and without semicolon let name = "Maxim"
  • 7. Declaration of constant immutable array let names : Array<String> = ["Maxim", "Anton"] let names : [String] = ["Maxim", "Anton"] let names = ["Maxim", "Anton"] names.append("Fox") // Compile error
  • 8. Declaration of mutable array (as variable) var names = ["Maxim", "Anton"] names.append("Fox") // ["Maxim", "Anton", "Fox"]
  • 9. Declaration of Optional value var name : Optional<String> = "Maxim" name!.isEmpty == false // ??? var name : String? = nil name?.isEmpty == false // ???
  • 10. Declaration of unwraped value if applicable var name : String? = nil if let _name = name { print("(_name)") } else { print("No name!") }
  • 11. Declaration of value which is only optional in the beginning var name : ImplicitlyUnwrappedOptional<String> = "Maxim" name.isEmpty var name : String! = nil name.isEmpty // Runtime Exception
  • 12. Decomposition of touples var a = 0, b = 0 let touple = (20, 30) a = touple.0 b = touple.1 // Or just like this: (a, b) = touple
  • 13. Convert from literal let url : NSURL = "http://nshipster.com/" "http://nshipster.com/".host
  • 14. extension NSURL: StringLiteralConvertible { public class func convertFromExtendedGraphemeClusterLiteral(value: String) -> Self { return self(string: value) } public class func convertFromStringLiteral(value: String) -> Self { return self(string: value) } }
  • 15. ▸ NilLiteralConvertible ▸ BooleanLiteralConvertible ▸ IntegerLiteralConvertible ▸ FloatLiteralConvertible ▸ StringLiteralConvertible / UnicodeScalarLiteralConvertible / ExtendedGraphemeClusterLiteralConvertible ▸ ArrayLiteralConvertible ▸ DictionaryLiteralConvertible
  • 17. Shortes function func f() -> Void {} func f() -> () {} func f() {}
  • 18. Function without parameter label func f(_ v : Int) -> Int { return v + 1 } func f(v : Int) -> Int { return v + 1 } let v1 = f(10) // v1 = 11
  • 19. Functoin with parameter label equal to parameter name func f(value value : Int) -> Int { return value + 1 } func f(#value : Int) -> Int { return value + 1 } let v1 = f(value : 10) // v1 = 11
  • 20. In/Out parameter func f(inout v : Int) { v + 1 } var v = 10 f(&v) // v = 11
  • 21. Copy parameter in to variable func f(var v : [String]) -> [String] { v.append("Anton") return v } let a = ["Maxim"] let a2 = f(a) // a = ["Maxim"] , a2 = ["Maxim", "Anton"]
  • 22. Rest parameter func sum(values:Int...) -> Int{ return values.reduce(0, +) } let sum1 = sum(1,2,3,4) // sum1 = 10 let sum2 = sum() // sum2 = 0
  • 23. Default parameter value func f(_ v : Int = 10) -> Int { return v + 1 } let v1 = f() // v1 = 11 let v2 = f(3) // v2 = 4
  • 24. Curried function func f(a : Int)(b : Int) -> Int { return a + b } let v1 = f(1)(2)
  • 25. Returning a closure (idea behind currying) func f(a : Int) -> (Int -> Int) { let f1 = { (b: Int) -> Int in return a + b } return f1 } let v1 = f(1)(2)
  • 26. Returning a closure (idea behind currying) func f(a : Int) -> (Int -> Int) { return { (b: Int) -> Int in return a + b } } let v1 = f(1)(2)
  • 27. Remove Closure types func f(a : Int) -> (Int -> Int) { return { b in return a + b } } let v1 = f(1)(2)
  • 28. Remove return keyword func f(a : Int) -> (Int -> Int) { return { b in a + b } } let v1 = f(1)(2)
  • 29. Remove parameter name func f(a : Int) -> (Int -> Int) { return { a + $0 } } let v1 = f(1)(2)
  • 30. Call a function with value func f(sum : Int) { print("sum is (sum)") } f(1 + 2) // f(3)
  • 31. Call function with closure enables lazy evaluation func f(sum : () -> Int) { print("sum is (sum())") } f({1 + 2}) // lazy evaluation
  • 32. Call function with auto closure enables lazy evaluation implicitly func f(sum : @autoclosure () -> Int) { print("sum is (sum())") } f(1 + 2) // still lazy evaluation
  • 33. If last operator is a function you can take it out of parenthesis func f(a : Int, b: Int, operation : (Int,Int) -> Int) { print("sum is ( operation(a, b) )") } f(1,2) { $0 + $1 }
  • 34. Or keep it func f(a : Int, b: Int, operation : (Int,Int) -> Int) { print("sum is ( operation(a, b) )") } f(1, 2, +)
  • 35. Operators are functions 1 + 2 infix operator + { associativity left precedence 140 } func +(lhs: Int, rhs: Int) -> Int
  • 36. Execution is based on precedence 1 + 2 * 4 infix operator + { associativity left precedence 140 } infix operator * { associativity left precedence 150 }
  • 38. Touple with named values can be used as structs typealias MyPoint = (x:Int, y:Int) let point : MyPoint = (x:25, y:30) point.x // 25 point.y // 30
  • 39. Struct with implicit intializer struct MyPoint { let x : Int let y : Int } let point = MyPoint(x:25, y:30) point.x // 25 point.y // 30
  • 40. Methods are curried functions struct MyName { let name : String init(_ n : String) { name = n } func desc()->String{ return "My name is: (name)" } } let myName = MyName("Maxim") myName.desc() MyName.desc(myName)()