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

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

What's hot (20)

The Ring programming language version 1.4.1 book - Part 22 of 31
The Ring programming language version 1.4.1 book - Part 22 of 31The Ring programming language version 1.4.1 book - Part 22 of 31
The Ring programming language version 1.4.1 book - Part 22 of 31
 
The Ring programming language version 1.6 book - Part 84 of 189
The Ring programming language version 1.6 book - Part 84 of 189The Ring programming language version 1.6 book - Part 84 of 189
The Ring programming language version 1.6 book - Part 84 of 189
 
Python meetup: coroutines, event loops, and non-blocking I/O
Python meetup: coroutines, event loops, and non-blocking I/OPython meetup: coroutines, event loops, and non-blocking I/O
Python meetup: coroutines, event loops, and non-blocking I/O
 
About Go
About GoAbout Go
About Go
 
A Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming LanguageA Few Interesting Things in Apple's Swift Programming Language
A Few Interesting Things in Apple's Swift Programming Language
 
Hacking Parse.y with ujihisa
Hacking Parse.y with ujihisaHacking Parse.y with ujihisa
Hacking Parse.y with ujihisa
 
Php 5.6
Php 5.6Php 5.6
Php 5.6
 
6. Generics. Collections. Streams
6. Generics. Collections. Streams6. Generics. Collections. Streams
6. Generics. Collections. Streams
 
Go a crash course
Go   a crash courseGo   a crash course
Go a crash course
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
 
Load-time Hacking using LD_PRELOAD
Load-time Hacking using LD_PRELOADLoad-time Hacking using LD_PRELOAD
Load-time Hacking using LD_PRELOAD
 
Implementing Software Machines in C and Go
Implementing Software Machines in C and GoImplementing Software Machines in C and Go
Implementing Software Machines in C and Go
 
8 arrays and pointers
8  arrays and pointers8  arrays and pointers
8 arrays and pointers
 
PHP 8.1: Enums
PHP 8.1: EnumsPHP 8.1: Enums
PHP 8.1: Enums
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
 
A Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP GeneratorsA Functional Guide to Cat Herding with PHP Generators
A Functional Guide to Cat Herding with PHP Generators
 
An introduction to functional programming with go
An introduction to functional programming with goAn introduction to functional programming with go
An introduction to functional programming with go
 

Similar to Hello Swift 3/5 - Function

Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
진성 오
 
Array Cont
Array ContArray Cont
functions
functionsfunctions
functions
Makwana Bhavesh
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloading
ankush_kumar
 
Generics and Inference
Generics and InferenceGenerics and Inference
Generics and Inference
Richard Fox
 
Functional Programming In Java
Functional Programming In JavaFunctional Programming In Java
Functional Programming In Java
Andrei Solntsev
 
Function in c
Function in cFunction in c
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
偉格 高
 
Function in c
Function in cFunction in c
Function in c
Raj Tandukar
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
Rumman Ansari
 
The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196
Mahmoud Samir Fayed
 
25-functions.ppt
25-functions.ppt25-functions.ppt
25-functions.ppt
JyothiAmpally
 
Function C++
Function C++ Function C++
Function C++
Shahzad Afridi
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Codemotion
 
C++ Functions.ppt
C++ Functions.pptC++ Functions.ppt
C++ Functions.ppt
WaheedAnwar20
 
Function recap
Function recapFunction recap
Function recap
alish sha
 
Function recap
Function recapFunction recap
Function recap
alish sha
 
C++ Function
C++ FunctionC++ Function
C++ Function
Hajar
 
ES6, WTF?
ES6, WTF?ES6, WTF?
ES6, WTF?
James Ford
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
temkin abdlkader
 

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

Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
 
Array Cont
Array ContArray Cont
Array Cont
 
functions
functionsfunctions
functions
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloading
 
Generics and Inference
Generics and InferenceGenerics and Inference
Generics and Inference
 
Functional Programming In Java
Functional Programming In JavaFunctional Programming In Java
Functional Programming In Java
 
Function in c
Function in cFunction in c
Function in c
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
 
Function in c
Function in cFunction in c
Function in c
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
 
The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196The Ring programming language version 1.7 book - Part 35 of 196
The Ring programming language version 1.7 book - Part 35 of 196
 
25-functions.ppt
25-functions.ppt25-functions.ppt
25-functions.ppt
 
Function C++
Function C++ Function C++
Function C++
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
 
C++ Functions.ppt
C++ Functions.pptC++ Functions.ppt
C++ Functions.ppt
 
Function recap
Function recapFunction recap
Function recap
 
Function recap
Function recapFunction recap
Function recap
 
C++ Function
C++ FunctionC++ Function
C++ Function
 
ES6, WTF?
ES6, WTF?ES6, WTF?
ES6, WTF?
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 

More from Cody Yun

Hello Swift Final
Hello Swift FinalHello Swift Final
Hello Swift Final
Cody Yun
 
Hello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and ClassesHello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and Classes
Cody Yun
 
Hello Swift 4/5 : Closure and Enum
Hello Swift 4/5 : Closure and EnumHello Swift 4/5 : Closure and Enum
Hello Swift 4/5 : Closure and Enum
Cody Yun
 
Hello Swift 2/5 - Basic2
Hello Swift 2/5 - Basic2Hello Swift 2/5 - Basic2
Hello Swift 2/5 - Basic2
Cody Yun
 
Hello Swift 1/5 - Basic1
Hello Swift 1/5 - Basic1Hello Swift 1/5 - Basic1
Hello Swift 1/5 - Basic1
Cody Yun
 
Unity3D Developer Network 4th
Unity3D Developer Network 4thUnity3D Developer Network 4th
Unity3D Developer Network 4th
Cody Yun
 
Unity3D Developer Network Study 3rd
Unity3D Developer Network Study 3rdUnity3D Developer Network Study 3rd
Unity3D Developer Network Study 3rd
Cody Yun
 
Unity3D - 툴 사용법
Unity3D - 툴 사용법Unity3D - 툴 사용법
Unity3D - 툴 사용법
Cody Yun
 
Unity3D Developer Network Study Chapter.2
Unity3D Developer Network Study Chapter.2Unity3D Developer Network Study Chapter.2
Unity3D Developer Network Study Chapter.2
Cody Yun
 

More from Cody Yun (9)

Hello Swift Final
Hello Swift FinalHello Swift Final
Hello Swift Final
 
Hello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and ClassesHello Swift Final 5/5 - Structures and Classes
Hello Swift Final 5/5 - Structures and Classes
 
Hello Swift 4/5 : Closure and Enum
Hello Swift 4/5 : Closure and EnumHello Swift 4/5 : Closure and Enum
Hello Swift 4/5 : Closure and Enum
 
Hello Swift 2/5 - Basic2
Hello Swift 2/5 - Basic2Hello Swift 2/5 - Basic2
Hello Swift 2/5 - Basic2
 
Hello Swift 1/5 - Basic1
Hello Swift 1/5 - Basic1Hello Swift 1/5 - Basic1
Hello Swift 1/5 - Basic1
 
Unity3D Developer Network 4th
Unity3D Developer Network 4thUnity3D Developer Network 4th
Unity3D Developer Network 4th
 
Unity3D Developer Network Study 3rd
Unity3D Developer Network Study 3rdUnity3D Developer Network Study 3rd
Unity3D Developer Network Study 3rd
 
Unity3D - 툴 사용법
Unity3D - 툴 사용법Unity3D - 툴 사용법
Unity3D - 툴 사용법
 
Unity3D Developer Network Study Chapter.2
Unity3D Developer Network Study Chapter.2Unity3D Developer Network Study Chapter.2
Unity3D Developer Network Study Chapter.2
 

Recently uploaded

The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
kalichargn70th171
 
What is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdfWhat is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdf
kalichargn70th171
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Streamlining End-to-End Testing Automation
Streamlining End-to-End Testing AutomationStreamlining End-to-End Testing Automation
Streamlining End-to-End Testing Automation
Anand Bagmar
 
Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...
Paul Brebner
 
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in NashikUpturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies
 
Penify - Let AI do the Documentation, you write the Code.
Penify - Let AI do the Documentation, you write the Code.Penify - Let AI do the Documentation, you write the Code.
Penify - Let AI do the Documentation, you write the Code.
KrishnaveniMohan1
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 
Software Test Automation - A Comprehensive Guide on Automated Testing.pdf
Software Test Automation - A Comprehensive Guide on Automated Testing.pdfSoftware Test Automation - A Comprehensive Guide on Automated Testing.pdf
Software Test Automation - A Comprehensive Guide on Automated Testing.pdf
kalichargn70th171
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
kgyxske
 
Stork Product Overview: An AI-Powered Autonomous Delivery Fleet
Stork Product Overview: An AI-Powered Autonomous Delivery FleetStork Product Overview: An AI-Powered Autonomous Delivery Fleet
Stork Product Overview: An AI-Powered Autonomous Delivery Fleet
Vince Scalabrino
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
Yara Milbes
 
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptxOperational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
sandeepmenon62
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
The Third Creative Media
 
Ensuring Efficiency and Speed with Practical Solutions for Clinical Operations
Ensuring Efficiency and Speed with Practical Solutions for Clinical OperationsEnsuring Efficiency and Speed with Practical Solutions for Clinical Operations
Ensuring Efficiency and Speed with Practical Solutions for Clinical Operations
OnePlan Solutions
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
ervikas4
 
Beginner's Guide to Observability@Devoxx PL 2024
Beginner's  Guide to Observability@Devoxx PL 2024Beginner's  Guide to Observability@Devoxx PL 2024
Beginner's Guide to Observability@Devoxx PL 2024
michniczscribd
 
Microsoft-Power-Platform-Adoption-Planning.pptx
Microsoft-Power-Platform-Adoption-Planning.pptxMicrosoft-Power-Platform-Adoption-Planning.pptx
Microsoft-Power-Platform-Adoption-Planning.pptx
jrodriguezq3110
 
Flutter vs. React Native: A Detailed Comparison for App Development in 2024
Flutter vs. React Native: A Detailed Comparison for App Development in 2024Flutter vs. React Native: A Detailed Comparison for App Development in 2024
Flutter vs. React Native: A Detailed Comparison for App Development in 2024
dhavalvaghelanectarb
 
Computer Science & Engineering VI Sem- New Syllabus.pdf
Computer Science & Engineering VI Sem- New Syllabus.pdfComputer Science & Engineering VI Sem- New Syllabus.pdf
Computer Science & Engineering VI Sem- New Syllabus.pdf
chandangoswami40933
 

Recently uploaded (20)

The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
The Power of Visual Regression Testing_ Why It Is Critical for Enterprise App...
 
What is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdfWhat is Continuous Testing in DevOps - A Definitive Guide.pdf
What is Continuous Testing in DevOps - A Definitive Guide.pdf
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Streamlining End-to-End Testing Automation
Streamlining End-to-End Testing AutomationStreamlining End-to-End Testing Automation
Streamlining End-to-End Testing Automation
 
Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...Superpower Your Apache Kafka Applications Development with Complementary Open...
Superpower Your Apache Kafka Applications Development with Complementary Open...
 
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in NashikUpturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in Nashik
 
Penify - Let AI do the Documentation, you write the Code.
Penify - Let AI do the Documentation, you write the Code.Penify - Let AI do the Documentation, you write the Code.
Penify - Let AI do the Documentation, you write the Code.
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 
Software Test Automation - A Comprehensive Guide on Automated Testing.pdf
Software Test Automation - A Comprehensive Guide on Automated Testing.pdfSoftware Test Automation - A Comprehensive Guide on Automated Testing.pdf
Software Test Automation - A Comprehensive Guide on Automated Testing.pdf
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
 
Stork Product Overview: An AI-Powered Autonomous Delivery Fleet
Stork Product Overview: An AI-Powered Autonomous Delivery FleetStork Product Overview: An AI-Powered Autonomous Delivery Fleet
Stork Product Overview: An AI-Powered Autonomous Delivery Fleet
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
 
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptxOperational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
Operational ease MuleSoft and Salesforce Service Cloud Solution v1.0.pptx
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
 
Ensuring Efficiency and Speed with Practical Solutions for Clinical Operations
Ensuring Efficiency and Speed with Practical Solutions for Clinical OperationsEnsuring Efficiency and Speed with Practical Solutions for Clinical Operations
Ensuring Efficiency and Speed with Practical Solutions for Clinical Operations
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
 
Beginner's Guide to Observability@Devoxx PL 2024
Beginner's  Guide to Observability@Devoxx PL 2024Beginner's  Guide to Observability@Devoxx PL 2024
Beginner's Guide to Observability@Devoxx PL 2024
 
Microsoft-Power-Platform-Adoption-Planning.pptx
Microsoft-Power-Platform-Adoption-Planning.pptxMicrosoft-Power-Platform-Adoption-Planning.pptx
Microsoft-Power-Platform-Adoption-Planning.pptx
 
Flutter vs. React Native: A Detailed Comparison for App Development in 2024
Flutter vs. React Native: A Detailed Comparison for App Development in 2024Flutter vs. React Native: A Detailed Comparison for App Development in 2024
Flutter vs. React Native: A Detailed Comparison for App Development in 2024
 
Computer Science & Engineering VI Sem- New Syllabus.pdf
Computer Science & Engineering VI Sem- New Syllabus.pdfComputer Science & Engineering VI Sem- New Syllabus.pdf
Computer Science & Engineering VI Sem- New Syllabus.pdf
 

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