SlideShare a Scribd company logo
Welcome to Swift
3/5
func sayHello(name name: String) {
println("Hello (name)")
}
1
•Function’s format
•Using the function
•Function with Tuple
•External Parameter Names
•Default Parameter Value
•Shorthand External Parameter Names
•Multiple Parameter
•In-Out Parameter
•Function type in Parameter and Return Type
다룰 내용
2
Function’s format
func helloFunc(param:String)->String {
let hello = "hello "+param
return hello
}
3
Function’s format
func helloFunc(param:String)->String {
let hello = "hello "+param
return hello
}
// declare function
4
Function’s format
func helloFunc(param:String)->String {
let hello = "hello "+param
return hello
}
// function name
5
Function’s format
func helloFunc(param:String)->String {
let hello = "hello "+param
return hello
}
// parameter’s name and parameter’s type
6
Function’s format
func helloFunc(param:String)->String {
let hello = "hello "+param
return hello
}
// function’s return type
7
Function’s format
func helloFunc(param:String)->String {
let hello = "hello "+param
return hello
}
//functions’s scope
8
Function’s format
func helloFunc(param:String)->String {
let hello = "hello "+param
return hello
}
//function’s logic
9
Function’s format
func helloFunc(param:String)->String {
let hello = "hello "+param
return hello
}
//return value in logic
10
Using the function
var returnValue = helloFunc("Cody")
11
Function with Tuple
import Foundation
func randomFunc(paramName:String)->(msg:String,random:Int) {
let hello = "hello "+paramName
let random = Int(arc4random()%8)
return (hello,random)
}
12
Function with Tuple
import Foundation
func randomFunc(paramName:String)->(msg:String,random:Int) {
let hello = "hello "+paramName
let random = Int(arc4random()%8)
return (hello,random)
}
13
Function with Tuple
import Foundation
func randomFunc(paramName:String)->(msg:String,random:Int) {
let hello = "hello "+paramName
let random = Int(arc4random()%8)
return (hello,random)
}
let tupleResult = randomFunc("Cody")
tupleResult.random
tupleResult.msg
14
Function with external parameter names
func join(s1: String, s2: String, s3: String) -> String {
return s1 + s3 + s2
}
func join(header s1: String, tail s2: String, joiner s3: String) -> String {
return s1 + s3 + s2
}
// What is different?
15
Function with external parameter names
func join(s1: String, s2: String, s3: String) -> String {
return s1 + s3 + s2
}
func join(header s1: String, tail s2: String, joiner s3: String) -> String {
return s1 + s3 + s2
}
// What is different?
16
Function with external parameter names
func join(s1: String, s2: String, s3: String) -> String {
return s1 + s3 + s2
}
func join(header s1: String, tail s2: String, joiner s3: String) -> String {
return s1 + s3 + s2
}
// Header, tail and join will use for calling the function
17
Function with external parameter names
func join(s1: String, s2: String, s3: String) -> String {
return s1 + s3 + s2
}
func join(header s1: String, tail s2: String, joiner s3: String) -> String {
return s1 + s3 + s2
}
// Header, tail and join will use for calling the function
join(header: "hello", tail: "world", joiner: ", ")
18
Function with external parameter names
func join(s1: String, s2: String, s3: String) -> String {
return s1 + s3 + s2
}
func join(header s1: String, tail s2: String, joiner s3: String) -> String {
return s1 + s3 + s2
}
// Header, tail and join will use for calling the function
join(header: "hello", tail: "world", joiner: ", ")
// When call function without external paramter names
join("hello","world",", ")
Missing argument labels 'header:tail:joiner:' in call
19
Function with shorthand external parameter names
func join(header s1: String, tail s2: String, joiner s3: String) -> String {
return s1 + s3 + s2
}
func join(#header: String, #tail: String, #joiner: String) -> String {
return header + joiner + tail
}
// What is different?
20
Function with shorthand external parameter names
func join(header s1: String, tail s2: String, joiner s3: String) -> String {
return s1 + s3 + s2
}
func join(#header: String, #tail: String, #joiner: String) -> String {
return header + joiner + tail
}
// What is different?
// header s1 > #header
// tail s2 > #tail
// joiner s3 > #joiner
// External parameter name is equal with local parameter name.
21
Function with default parameter value
func join(header s1: String, tail s2: String, joiner s3: String=" ") ->
String {
return s1 + s3 + s2
}
join(s1: "hello", s2: "world", s3: ", ")
join(s1: "hello", s2: "world")
22
Function with constant value
func sayHello(let param:String)->String {
param = "test"
let hello = "hello "+param
return hello
}
let name = "Cody"
var returnValue = sayHello(name)
23
Function with constant value
func helloFunc(let param:String)->String {
param = "test"
let hello = "hello "+param
return hello
}
let name = "Cody"
var returnValue = helloFunc(name)
Cannot assign to ‘let’ value ‘param’
24
Function with multiple parameter
func sum(numbers: Int...) -> Int {
var total: Int = 0
for number in numbers {
total += number
}
return total
}
sum(1, 2, 3, 4, 5)
25
Function with multiple parameter
func sum(numbers: Int...) -> Int {
var total: Int = 0
for number in numbers {
total += number
}
return total
}
sum(1, 2, 3, 4, 5)
26
Function with in-out parameter
func swapTwoInt(inout a: Int, inout b: Int) {
let temp = a
a = b
b = temp
}
var numA = 1
var numB = 2
swapTwoInts(&numA,&numB)
numA
numB
// In C++ called “call by reference”
27
Function with in-out parameter
// 물론 in-out parameter를 shorthands external parameter name과
// 함께 사용할 수도 있습니다.
func swapTwoInt(inout #a: Int, inout #b: Int) {
let temp = a
a = b
b = temp
}
var numA = 1
var numB = 2
swapTwoInts(a:&numA,b:&numB)
numA
numB
28
Function with in-out parameter
func swapTwoInt(inout a: Int, inout b: Int) {
let temp = a
a = b
b = temp
}
var numA = 1
var numB = 2
swapTwoInts(&numA,&numB)
numA
numB
// In C++ called “call by reference”
29
Function with in-out parameter
// 물론 in-out parameter를 shorthands external parameter name과
// 함께 사용할 수도 있습니다.
func swapTwoInt(inout #a: Int, inout #b: Int) {
let temp = a
a = b
b = temp
}
var numA = 1
var numB = 2
swapTwoInts(a:&numA,b:&numB)
numA
numB
30
Function types
func addTwoInts(a: Int, b: Int) -> Int {
return a + b
}
var mathFunction: (Int, Int) -> Int = addTwoInts
mathFunction(10,20)
31
Function types in parameter
func printFunctionResult(mathFunction: (Int, Int) -> Int) {
println("Result is (mathFunction(10,10))")
}
func addTwoInts(a: Int, b: Int) -> Int {
return a + b
}
var mathFunction: (Int, Int) -> Int = addTwoInts
printFunctionResult(mathFunction)
32
Function types in parameter
// 사실 function을 변수에 assign해서 넘길 필요가 없어요
func printFunctionResult(mathFunction: (Int, Int) -> Int) {
println("Result is (mathFunction(10,10))")
}
func addTwoInts(a: Int, b: Int) -> Int {
return a + b
}
printFunctionResult(addTwoInts)
33
Function types in return type
func stepForward(input: Int) -> Int {
return input + 1
}
func stepBackward(input: Int) -> Int {
return input - 1
}
func chooseStepFunction(backwards: Bool) -> (Int) -> Int {
return backwards ? stepBackward : stepForward
}
34
Nested function
func chooseStepFunction(backwards: Bool) -> (Int) -> Int {
func stepForward(input: Int) -> Int {
return input + 1
}
func stepBackward(input: Int) -> Int {
return input - 1
}
return backwards ? stepBackward : stepForward
}
35
내일은?
• Enumeration
• Closures
• Structures and Classes
- Initializers and Deinitialization in Classes
- Properties
- Subscripts
- Inheritance
- Subclassing
- Overriding and Preventing Overrides
36
감사합니다.
let writer = ["Cody":"Yun"]
37

More Related Content

What's hot (20)

PDF
The Ring programming language version 1.4.1 book - Part 22 of 31
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.6 book - Part 84 of 189
Mahmoud Samir Fayed
 
PDF
Python meetup: coroutines, event loops, and non-blocking I/O
Buzzcapture
 
PPT
About Go
Jongmin Kim
 
PPTX
A Few Interesting Things in Apple's Swift Programming Language
SmartLogic
 
PDF
Hacking Parse.y with ujihisa
ujihisa
 
PDF
6. Generics. Collections. Streams
DEVTYPE
 
PDF
Go a crash course
Eleanor McHugh
 
PDF
Code Generation in PHP - PHPConf 2015
Lin Yo-An
 
PDF
Swift Programming Language
Giuseppe Arici
 
PDF
Are we ready to Go?
Adam Dudczak
 
PPTX
Load-time Hacking using LD_PRELOAD
Dharmalingam Ganesan
 
PDF
Implementing Software Machines in C and Go
Eleanor McHugh
 
PDF
8 arrays and pointers
MomenMostafa
 
PDF
PHP 8.1: Enums
Ayesh Karunaratne
 
PDF
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
kinan keshkeh
 
PDF
All I know about rsc.io/c2go
Moriyoshi Koizumi
 
PPTX
A Functional Guide to Cat Herding with PHP Generators
Mark Baker
 
PDF
An introduction to functional programming with go
Eleanor McHugh
 
The Ring programming language version 1.4.1 book - Part 22 of 31
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 84 of 189
Mahmoud Samir Fayed
 
Python meetup: coroutines, event loops, and non-blocking I/O
Buzzcapture
 
About Go
Jongmin Kim
 
A Few Interesting Things in Apple's Swift Programming Language
SmartLogic
 
Hacking Parse.y with ujihisa
ujihisa
 
6. Generics. Collections. Streams
DEVTYPE
 
Go a crash course
Eleanor McHugh
 
Code Generation in PHP - PHPConf 2015
Lin Yo-An
 
Swift Programming Language
Giuseppe Arici
 
Are we ready to Go?
Adam Dudczak
 
Load-time Hacking using LD_PRELOAD
Dharmalingam Ganesan
 
Implementing Software Machines in C and Go
Eleanor McHugh
 
8 arrays and pointers
MomenMostafa
 
PHP 8.1: Enums
Ayesh Karunaratne
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
kinan keshkeh
 
All I know about rsc.io/c2go
Moriyoshi Koizumi
 
A Functional Guide to Cat Herding with PHP Generators
Mark Baker
 
An introduction to functional programming with go
Eleanor McHugh
 

Similar to Hello Swift 3/5 - Function (20)

PDF
Swift 함수 커링 사용하기
진성 오
 
DOCX
Array Cont
Ashutosh Srivasatava
 
PPTX
functions
Makwana Bhavesh
 
PPTX
Classes function overloading
ankush_kumar
 
PDF
Generics and Inference
Richard Fox
 
PPT
Functional Programming In Java
Andrei Solntsev
 
PPTX
Function in c
CGC Technical campus,Mohali
 
PPTX
C++ Functions | Introduction to programming
mahidazad00
 
PDF
Functional programming using underscorejs
偉格 高
 
PPTX
Function in c
Raj Tandukar
 
PPTX
C Programming Language Part 7
Rumman Ansari
 
PDF
The Ring programming language version 1.7 book - Part 35 of 196
Mahmoud Samir Fayed
 
PPT
25-functions.ppt
JyothiAmpally
 
PPTX
Function C++
Shahzad Afridi
 
PPTX
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Codemotion
 
PPT
C++ Functions.ppt
WaheedAnwar20
 
PPTX
Function recap
alish sha
 
PPTX
Function recap
alish sha
 
PPT
C++ Function
Hajar
 
PDF
ES6, WTF?
James Ford
 
Swift 함수 커링 사용하기
진성 오
 
functions
Makwana Bhavesh
 
Classes function overloading
ankush_kumar
 
Generics and Inference
Richard Fox
 
Functional Programming In Java
Andrei Solntsev
 
C++ Functions | Introduction to programming
mahidazad00
 
Functional programming using underscorejs
偉格 高
 
Function in c
Raj Tandukar
 
C Programming Language Part 7
Rumman Ansari
 
The Ring programming language version 1.7 book - Part 35 of 196
Mahmoud Samir Fayed
 
25-functions.ppt
JyothiAmpally
 
Function C++
Shahzad Afridi
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Codemotion
 
C++ Functions.ppt
WaheedAnwar20
 
Function recap
alish sha
 
Function recap
alish sha
 
C++ Function
Hajar
 
ES6, WTF?
James Ford
 
Ad

More from Cody Yun (9)

PDF
Hello Swift Final
Cody Yun
 
PDF
Hello Swift Final 5/5 - Structures and Classes
Cody Yun
 
PDF
Hello Swift 4/5 : Closure and Enum
Cody Yun
 
PDF
Hello Swift 2/5 - Basic2
Cody Yun
 
PDF
Hello Swift 1/5 - Basic1
Cody Yun
 
KEY
Unity3D Developer Network 4th
Cody Yun
 
PDF
Unity3D Developer Network Study 3rd
Cody Yun
 
KEY
Unity3D - 툴 사용법
Cody Yun
 
PDF
Unity3D Developer Network Study Chapter.2
Cody Yun
 
Hello Swift Final
Cody Yun
 
Hello Swift Final 5/5 - Structures and Classes
Cody Yun
 
Hello Swift 4/5 : Closure and Enum
Cody Yun
 
Hello Swift 2/5 - Basic2
Cody Yun
 
Hello Swift 1/5 - Basic1
Cody Yun
 
Unity3D Developer Network 4th
Cody Yun
 
Unity3D Developer Network Study 3rd
Cody Yun
 
Unity3D - 툴 사용법
Cody Yun
 
Unity3D Developer Network Study Chapter.2
Cody Yun
 
Ad

Recently uploaded (20)

PPTX
Automatic_Iperf_Log_Result_Excel_visual_v2.pptx
Chen-Chih Lee
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PDF
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
PPTX
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
 
PDF
Transform Retail with Smart Technology: Power Your Growth with Ginesys
Ginesys
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PPTX
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 
PDF
Dealing with JSON in the relational world
Andres Almiray
 
PDF
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PDF
From Chaos to Clarity: Mastering Analytics Governance in the Modern Enterprise
Wiiisdom
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PPTX
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
 
PPTX
PowerISO Crack 2025 – Free Download Full Version with Serial Key [Latest](1)....
HyperPc soft
 
PDF
2025年 Linux 核心專題: 探討 sched_ext 及機器學習.pdf
Eric Chou
 
PDF
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Automatic_Iperf_Log_Result_Excel_visual_v2.pptx
Chen-Chih Lee
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
 
Transform Retail with Smart Technology: Power Your Growth with Ginesys
Ginesys
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 
Dealing with JSON in the relational world
Andres Almiray
 
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
From Chaos to Clarity: Mastering Analytics Governance in the Modern Enterprise
Wiiisdom
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
 
PowerISO Crack 2025 – Free Download Full Version with Serial Key [Latest](1)....
HyperPc soft
 
2025年 Linux 核心專題: 探討 sched_ext 及機器學習.pdf
Eric Chou
 
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 

Hello Swift 3/5 - Function

  • 1. Welcome to Swift 3/5 func sayHello(name name: String) { println("Hello (name)") } 1
  • 2. •Function’s format •Using the function •Function with Tuple •External Parameter Names •Default Parameter Value •Shorthand External Parameter Names •Multiple Parameter •In-Out Parameter •Function type in Parameter and Return Type 다룰 내용 2
  • 3. Function’s format func helloFunc(param:String)->String { let hello = "hello "+param return hello } 3
  • 4. Function’s format func helloFunc(param:String)->String { let hello = "hello "+param return hello } // declare function 4
  • 5. Function’s format func helloFunc(param:String)->String { let hello = "hello "+param return hello } // function name 5
  • 6. Function’s format func helloFunc(param:String)->String { let hello = "hello "+param return hello } // parameter’s name and parameter’s type 6
  • 7. Function’s format func helloFunc(param:String)->String { let hello = "hello "+param return hello } // function’s return type 7
  • 8. Function’s format func helloFunc(param:String)->String { let hello = "hello "+param return hello } //functions’s scope 8
  • 9. Function’s format func helloFunc(param:String)->String { let hello = "hello "+param return hello } //function’s logic 9
  • 10. Function’s format func helloFunc(param:String)->String { let hello = "hello "+param return hello } //return value in logic 10
  • 11. Using the function var returnValue = helloFunc("Cody") 11
  • 12. Function with Tuple import Foundation func randomFunc(paramName:String)->(msg:String,random:Int) { let hello = "hello "+paramName let random = Int(arc4random()%8) return (hello,random) } 12
  • 13. Function with Tuple import Foundation func randomFunc(paramName:String)->(msg:String,random:Int) { let hello = "hello "+paramName let random = Int(arc4random()%8) return (hello,random) } 13
  • 14. Function with Tuple import Foundation func randomFunc(paramName:String)->(msg:String,random:Int) { let hello = "hello "+paramName let random = Int(arc4random()%8) return (hello,random) } let tupleResult = randomFunc("Cody") tupleResult.random tupleResult.msg 14
  • 15. Function with external parameter names func join(s1: String, s2: String, s3: String) -> String { return s1 + s3 + s2 } func join(header s1: String, tail s2: String, joiner s3: String) -> String { return s1 + s3 + s2 } // What is different? 15
  • 16. Function with external parameter names func join(s1: String, s2: String, s3: String) -> String { return s1 + s3 + s2 } func join(header s1: String, tail s2: String, joiner s3: String) -> String { return s1 + s3 + s2 } // What is different? 16
  • 17. Function with external parameter names func join(s1: String, s2: String, s3: String) -> String { return s1 + s3 + s2 } func join(header s1: String, tail s2: String, joiner s3: String) -> String { return s1 + s3 + s2 } // Header, tail and join will use for calling the function 17
  • 18. Function with external parameter names func join(s1: String, s2: String, s3: String) -> String { return s1 + s3 + s2 } func join(header s1: String, tail s2: String, joiner s3: String) -> String { return s1 + s3 + s2 } // Header, tail and join will use for calling the function join(header: "hello", tail: "world", joiner: ", ") 18
  • 19. Function with external parameter names func join(s1: String, s2: String, s3: String) -> String { return s1 + s3 + s2 } func join(header s1: String, tail s2: String, joiner s3: String) -> String { return s1 + s3 + s2 } // Header, tail and join will use for calling the function join(header: "hello", tail: "world", joiner: ", ") // When call function without external paramter names join("hello","world",", ") Missing argument labels 'header:tail:joiner:' in call 19
  • 20. Function with shorthand external parameter names func join(header s1: String, tail s2: String, joiner s3: String) -> String { return s1 + s3 + s2 } func join(#header: String, #tail: String, #joiner: String) -> String { return header + joiner + tail } // What is different? 20
  • 21. Function with shorthand external parameter names func join(header s1: String, tail s2: String, joiner s3: String) -> String { return s1 + s3 + s2 } func join(#header: String, #tail: String, #joiner: String) -> String { return header + joiner + tail } // What is different? // header s1 > #header // tail s2 > #tail // joiner s3 > #joiner // External parameter name is equal with local parameter name. 21
  • 22. Function with default parameter value func join(header s1: String, tail s2: String, joiner s3: String=" ") -> String { return s1 + s3 + s2 } join(s1: "hello", s2: "world", s3: ", ") join(s1: "hello", s2: "world") 22
  • 23. Function with constant value func sayHello(let param:String)->String { param = "test" let hello = "hello "+param return hello } let name = "Cody" var returnValue = sayHello(name) 23
  • 24. Function with constant value func helloFunc(let param:String)->String { param = "test" let hello = "hello "+param return hello } let name = "Cody" var returnValue = helloFunc(name) Cannot assign to ‘let’ value ‘param’ 24
  • 25. Function with multiple parameter func sum(numbers: Int...) -> Int { var total: Int = 0 for number in numbers { total += number } return total } sum(1, 2, 3, 4, 5) 25
  • 26. Function with multiple parameter func sum(numbers: Int...) -> Int { var total: Int = 0 for number in numbers { total += number } return total } sum(1, 2, 3, 4, 5) 26
  • 27. Function with in-out parameter func swapTwoInt(inout a: Int, inout b: Int) { let temp = a a = b b = temp } var numA = 1 var numB = 2 swapTwoInts(&numA,&numB) numA numB // In C++ called “call by reference” 27
  • 28. Function with in-out parameter // 물론 in-out parameter를 shorthands external parameter name과 // 함께 사용할 수도 있습니다. func swapTwoInt(inout #a: Int, inout #b: Int) { let temp = a a = b b = temp } var numA = 1 var numB = 2 swapTwoInts(a:&numA,b:&numB) numA numB 28
  • 29. Function with in-out parameter func swapTwoInt(inout a: Int, inout b: Int) { let temp = a a = b b = temp } var numA = 1 var numB = 2 swapTwoInts(&numA,&numB) numA numB // In C++ called “call by reference” 29
  • 30. Function with in-out parameter // 물론 in-out parameter를 shorthands external parameter name과 // 함께 사용할 수도 있습니다. func swapTwoInt(inout #a: Int, inout #b: Int) { let temp = a a = b b = temp } var numA = 1 var numB = 2 swapTwoInts(a:&numA,b:&numB) numA numB 30
  • 31. Function types func addTwoInts(a: Int, b: Int) -> Int { return a + b } var mathFunction: (Int, Int) -> Int = addTwoInts mathFunction(10,20) 31
  • 32. Function types in parameter func printFunctionResult(mathFunction: (Int, Int) -> Int) { println("Result is (mathFunction(10,10))") } func addTwoInts(a: Int, b: Int) -> Int { return a + b } var mathFunction: (Int, Int) -> Int = addTwoInts printFunctionResult(mathFunction) 32
  • 33. Function types in parameter // 사실 function을 변수에 assign해서 넘길 필요가 없어요 func printFunctionResult(mathFunction: (Int, Int) -> Int) { println("Result is (mathFunction(10,10))") } func addTwoInts(a: Int, b: Int) -> Int { return a + b } printFunctionResult(addTwoInts) 33
  • 34. Function types in return type func stepForward(input: Int) -> Int { return input + 1 } func stepBackward(input: Int) -> Int { return input - 1 } func chooseStepFunction(backwards: Bool) -> (Int) -> Int { return backwards ? stepBackward : stepForward } 34
  • 35. Nested function func chooseStepFunction(backwards: Bool) -> (Int) -> Int { func stepForward(input: Int) -> Int { return input + 1 } func stepBackward(input: Int) -> Int { return input - 1 } return backwards ? stepBackward : stepForward } 35
  • 36. 내일은? • Enumeration • Closures • Structures and Classes - Initializers and Deinitialization in Classes - Properties - Subscripts - Inheritance - Subclassing - Overriding and Preventing Overrides 36
  • 37. 감사합니다. let writer = ["Cody":"Yun"] 37