SlideShare una empresa de Scribd logo
1 de 42
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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 a 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 a 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
 

Más de 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
 

Más de 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
 

Último

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 

Último (20)

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 

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)()