SlideShare a Scribd company logo
6. Swift 기초
- 고급 함수
창원대학교 정보통신공학과 박동규
2015. 12
함수 레이블
• Swift에서 두개 이상의 매개변수를 가진 함수를 호출할
때는 반드시 두번째 매개변수부터 레이블을 적어주어야
한다( Swift 2.0 이후 )
• 레이블은 매개변수의 목적이나 기능을 명시하여 코드를
더 읽기 쉽게 만들고 에러를 줄이는데 도움이 된다
함수 레이블
함수 레이블
vs
함수 레이블
vs
join 함수를 통해 매개변수로 입력된 String을 조합할 수 있다
매개변수가 2개 이상이면 두번째 매개변수는 반드시 레이블링을 해야한다.
레이블링을 통해 매개변수의 역할을 명확하게 이해할 수 있다.
Objective-C와의 호환성을 확보할 수 있다
함수 레이블
vs
join 함수를 통해 매개변수로 입력된 String을 조합할 수 있다
매개변수가 2개 이상이면 두번째 매개변수는 반드시 레이블링을 해야한다.
레이블링을 통해 매개변수의 역할을 명확하게 이해할 수 있다.
Objective-C와의 호환성을 확보할 수 있다
함수 레이블
vs
join 함수를 통해 매개변수로 입력된 String을 조합할 수 있다
매개변수가 2개 이상이면 두번째 매개변수는 반드시 레이블링을 해야한다.
레이블링을 통해 매개변수의 역할을 명확하게 이해할 수 있다.
Objective-C와의 호환성을 확보할 수 있다
가변인자(variadic) 함수
• 함수구문에서 함수에 전달되는 매개변수의 수를 정확하
게 알 수 없을 경우에 사용하는 문법으로 ... 으로 표시
가변인자(variadic) 함수
• 함수구문에서 함수에 전달되는 매개변수의 수를 정확하
게 알 수 없을 경우에 사용하는 문법으로 ... 으로 표시
함수 타입(형)
(Int, Int) 타입 매개변수를 입력으로 받아서 Int형 값을
반환하는 함수임
함수 타입
• 함수타입(형)의 상수나 변수를 만들어 함수를 할당할
(assign) 수 있음
두	개의	Int	값을	매개변수로	취하며	Int	값을	반환하는	함수타입(형)	
변수	mathFuntion을	선언하고,	이	변수가	addTwoInts	함수를	참조(refer)
하도록	한다.
함수 타입
함수 타입
함수 타입
함수 타입 변수 mathFunction
함수 타입
Result: 5
함수 타입 변수 mathFunction
함수 타입
Swift의 함수 타입
두	개의	Int	값을	매개변수로	취하고	Int	값을	반환하는	함수	타입	변
수	mathFuntion을	newMathFunction	변수가	참조한다
C 언어의 함수 포인터
C 언어의 함수 포인터
mathFunction, newMathFunction은 함수의 주소를
담을 수 있는 변수 -> 함수 포인터
C 언어의 함수 포인터
…	
int	addTwoInts(int	a,	int	b)	{	
				return	a	+	b;	
}	
int	main(int	argc,	const	char	*	argv[])	{	
				int	(*mathFunction)(int,	int)	=	&addTwoInts;	
				int	(*newMathFunction)(int,	int);	
				newMathFunction	=	mathFunction;	
					
…
C 언어의 함수 포인터
…	
int	addTwoInts(int	a,	int	b)	{	
				return	a	+	b;	
}	
int	main(int	argc,	const	char	*	argv[])	{	
				int	(*mathFunction)(int,	int)	=	&addTwoInts;	
				int	(*newMathFunction)(int,	int);	
				newMathFunction	=	mathFunction;	
					
…
C 언어의 함수 포인터
…	
int	addTwoInts(int	a,	int	b)	{	
				return	a	+	b;	
}	
int	main(int	argc,	const	char	*	argv[])	{	
				int	(*mathFunction)(int,	int)	=	&addTwoInts;	
				int	(*newMathFunction)(int,	int);	
				newMathFunction	=	mathFunction;	
					
…
C 언어의 함수
C 언어의 함수 포인터
…	
int	addTwoInts(int	a,	int	b)	{	
				return	a	+	b;	
}	
int	main(int	argc,	const	char	*	argv[])	{	
				int	(*mathFunction)(int,	int)	=	&addTwoInts;	
				int	(*newMathFunction)(int,	int);	
				newMathFunction	=	mathFunction;	
					
…
C 언어의 함수
C 언어의 함수 포인터
…	
int	addTwoInts(int	a,	int	b)	{	
				return	a	+	b;	
}	
int	main(int	argc,	const	char	*	argv[])	{	
				int	(*mathFunction)(int,	int)	=	&addTwoInts;	
				int	(*newMathFunction)(int,	int);	
				newMathFunction	=	mathFunction;	
					
…
C 언어의 함수 포인터
…	
int	addTwoInts(int	a,	int	b)	{	
				return	a	+	b;	
}	
int	main(int	argc,	const	char	*	argv[])	{	
				int	(*mathFunction)(int,	int)	=	&addTwoInts;	
				int	(*newMathFunction)(int,	int);	
				newMathFunction	=	mathFunction;	
					
…
C 언어의 함수 포인터
…	
int	addTwoInts(int	a,	int	b)	{	
				return	a	+	b;	
}	
int	main(int	argc,	const	char	*	argv[])	{	
				int	(*mathFunction)(int,	int)	=	&addTwoInts;	
				int	(*newMathFunction)(int,	int);	
				newMathFunction	=	mathFunction;	
					
…
함수 포인터
C 언어의 함수 포인터
…	
int	addTwoInts(int	a,	int	b)	{	
				return	a	+	b;	
}	
int	main(int	argc,	const	char	*	argv[])	{	
				int	(*mathFunction)(int,	int)	=	&addTwoInts;	
				int	(*newMathFunction)(int,	int);	
				newMathFunction	=	mathFunction;	
					
…
함수 포인터
C 언어의 함수 포인터
…	
int	addTwoInts(int	a,	int	b)	{	
				return	a	+	b;	
}	
int	main(int	argc,	const	char	*	argv[])	{	
				int	(*mathFunction)(int,	int)	=	&addTwoInts;	
				int	(*newMathFunction)(int,	int);	
				newMathFunction	=	mathFunction;	
					
…
C 언어의 함수 포인터
…	
int	addTwoInts(int	a,	int	b)	{	
				return	a	+	b;	
}	
int	main(int	argc,	const	char	*	argv[])	{	
				int	(*mathFunction)(int,	int)	=	&addTwoInts;	
				int	(*newMathFunction)(int,	int);	
				newMathFunction	=	mathFunction;	
					
…
C 언어의 함수 포인터
…	
int	addTwoInts(int	a,	int	b)	{	
				return	a	+	b;	
}	
int	main(int	argc,	const	char	*	argv[])	{	
				int	(*mathFunction)(int,	int)	=	&addTwoInts;	
				int	(*newMathFunction)(int,	int);	
				newMathFunction	=	mathFunction;	
					
…
함수 포인터
C 언어의 함수 포인터
…	
int	addTwoInts(int	a,	int	b)	{	
				return	a	+	b;	
}	
int	main(int	argc,	const	char	*	argv[])	{	
				int	(*mathFunction)(int,	int)	=	&addTwoInts;	
				int	(*newMathFunction)(int,	int);	
				newMathFunction	=	mathFunction;	
					
…
함수 포인터
C 언어의 함수 포인터
…	
int	addTwoInts(int	a,	int	b)	{	
				return	a	+	b;	
}	
int	main(int	argc,	const	char	*	argv[])	{	
				int	(*mathFunction)(int,	int)	=	&addTwoInts;	
				int	(*newMathFunction)(int,	int);	
				newMathFunction	=	mathFunction;	
					
…
C 언어의 함수 포인터
…	
int	addTwoInts(int	a,	int	b)	{	
				return	a	+	b;	
}	
int	main(int	argc,	const	char	*	argv[])	{	
				int	(*mathFunction)(int,	int)	=	&addTwoInts;	
				int	(*newMathFunction)(int,	int);	
				newMathFunction	=	mathFunction;	
					
…
C 언어의 함수 포인터
…	
int	addTwoInts(int	a,	int	b)	{	
				return	a	+	b;	
}	
int	main(int	argc,	const	char	*	argv[])	{	
				int	(*mathFunction)(int,	int)	=	&addTwoInts;	
				int	(*newMathFunction)(int,	int);	
				newMathFunction	=	mathFunction;	
					
… 함수 포인터를 다른 함수 포인터에 복사할 수 있음
함수형을 매개변수로 사용
함수형을 매개변수로 사용
함수형을 매개변수로 사용
함수의 반환
함수의 반환
Int형 값을 매개변수로 받아 Int 값을
반환하는 함수
함수의 반환
Int형 값을 매개변수로 받아 Int 값을
반환하는 함수
Int형 값을 매개변수로 받아 Int 값을
반환하는 함수
함수의 반환
Int형 값을 매개변수로 받아 Int 값을
반환하는 함수
Int형 값을 매개변수로 받아 Int 값을
반환하는 함수
함수의 반환
반환형- Int형을 매개변수로 받아 Int
값을 반환하는 함수
Int형 값을 매개변수로 받아 Int 값을
반환하는 함수
Int형 값을 매개변수로 받아 Int 값을
반환하는 함수
함수의 반환
반환형- Int형을 매개변수로 받아 Int
값을 반환하는 함수
Int형 값을 매개변수로 받아 Int 값을
반환하는 함수
Int형 값을 매개변수로 받아 Int 값을
반환하는 함수
함수의 반환
반환형- Int형을 매개변수로 받아 Int
값을 반환하는 함수
Int형 값을 매개변수로 받아 Int 값을
반환하는 함수
Int형 값을 매개변수로 받아 Int 값을
반환하는 함수
함수의 반환
매개변수 backwards가 true이면 stepBackward 함
수를, false이면 stepForward 함수를 반환한다
반환형- Int형을 매개변수로 받아 Int
값을 반환하는 함수
Int형 값을 매개변수로 받아 Int 값을
반환하는 함수
Int형 값을 매개변수로 받아 Int 값을
반환하는 함수
중첩 함수
• 함수 내부에 다른 함수를 중첩할 수 있다
중첩 함수
• 함수 내부에 다른 함수를 중첩할 수 있다
중첩 함수
• 함수 내부에 다른 함수를 중첩할 수 있다
반환형은 Int를 매개변수로 받아 Int형
중첩 함수
• 함수 내부에 다른 함수를 중첩할 수 있다
반환형은 Int를 매개변수로 받아 Int형
값을 반환하는 함수
정리
• 함수의 매개변수가 가변적일 경우 - variadic 문법
• 함수형의 상수나 변수를 만들어 함수를 할당할 수 있음
• 중첩함수를 만들 수 있음
• 함수 내부에서 정의한 함수형을 반환할 수 있음
• C의 함수 포인터보다 간단하면서도 강력한 기능
감사합니다
dongupak@gmail.com

More Related Content

What's hot

자바 8 학습
자바 8 학습자바 8 학습
자바 8 학습
HeeChang Lee
 
Template at c++
Template at c++Template at c++
Template at c++
Lusain Kim
 
9 swift 클로저1
9 swift 클로저19 swift 클로저1
9 swift 클로저1
Changwon National University
 
Swift3 subscript inheritance initialization
Swift3 subscript inheritance initializationSwift3 subscript inheritance initialization
Swift3 subscript inheritance initialization
Eunjoo Im
 
자바8 람다식 소개
자바8 람다식 소개자바8 람다식 소개
자바8 람다식 소개
beom kyun choi
 
Swift3 generic
Swift3 genericSwift3 generic
Swift3 generic
Eunjoo Im
 
Swift3 typecasting nested_type
Swift3 typecasting nested_typeSwift3 typecasting nested_type
Swift3 typecasting nested_type
Eunjoo Im
 
C++11
C++11C++11
C++11
선협 이
 
[C++ Korea 2nd Seminar] C++17 Key Features Summary
[C++ Korea 2nd Seminar] C++17 Key Features Summary[C++ Korea 2nd Seminar] C++17 Key Features Summary
[C++ Korea 2nd Seminar] C++17 Key Features Summary
Chris Ohk
 
[devil's camp] - 알고리즘 대회와 STL (박인서)
[devil's camp] - 알고리즘 대회와 STL (박인서)[devil's camp] - 알고리즘 대회와 STL (박인서)
[devil's camp] - 알고리즘 대회와 STL (박인서)
NAVER D2
 
스위프트 성능 이해하기
스위프트 성능 이해하기스위프트 성능 이해하기
스위프트 성능 이해하기
Yongha Yoo
 
C++에서 Objective-C까지
C++에서 Objective-C까지C++에서 Objective-C까지
C++에서 Objective-C까지
Changwon National University
 
프로그래밍 대회: C++11 이야기
프로그래밍 대회: C++11 이야기프로그래밍 대회: C++11 이야기
프로그래밍 대회: C++11 이야기
Jongwook Choi
 
8 swift 중첩함수
8 swift 중첩함수8 swift 중첩함수
8 swift 중첩함수
Changwon National University
 
C++ 11 에 대해서 쉽게 알아봅시다 1부
C++ 11 에 대해서 쉽게 알아봅시다 1부C++ 11 에 대해서 쉽게 알아봅시다 1부
C++ 11 에 대해서 쉽게 알아봅시다 1부
Gwangwhi Mah
 
Startup JavaScript 5 - 객체(Date, RegExp, Object, Global)
Startup JavaScript 5 - 객체(Date, RegExp, Object, Global)Startup JavaScript 5 - 객체(Date, RegExp, Object, Global)
Startup JavaScript 5 - 객체(Date, RegExp, Object, Global)
Circulus
 
자바8강의 2강. Stream API
자바8강의 2강. Stream API자바8강의 2강. Stream API
자바8강의 2강. Stream API
Sejong Park
 
Realm.io for iOS
Realm.io for iOSRealm.io for iOS
Realm.io for iOS
Eunjoo Im
 
Do swift: Swift 무작정 해보기
Do swift: Swift 무작정 해보기Do swift: Swift 무작정 해보기
Do swift: Swift 무작정 해보기
YoonBong Steve Kim
 
Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심흥배 최
 

What's hot (20)

자바 8 학습
자바 8 학습자바 8 학습
자바 8 학습
 
Template at c++
Template at c++Template at c++
Template at c++
 
9 swift 클로저1
9 swift 클로저19 swift 클로저1
9 swift 클로저1
 
Swift3 subscript inheritance initialization
Swift3 subscript inheritance initializationSwift3 subscript inheritance initialization
Swift3 subscript inheritance initialization
 
자바8 람다식 소개
자바8 람다식 소개자바8 람다식 소개
자바8 람다식 소개
 
Swift3 generic
Swift3 genericSwift3 generic
Swift3 generic
 
Swift3 typecasting nested_type
Swift3 typecasting nested_typeSwift3 typecasting nested_type
Swift3 typecasting nested_type
 
C++11
C++11C++11
C++11
 
[C++ Korea 2nd Seminar] C++17 Key Features Summary
[C++ Korea 2nd Seminar] C++17 Key Features Summary[C++ Korea 2nd Seminar] C++17 Key Features Summary
[C++ Korea 2nd Seminar] C++17 Key Features Summary
 
[devil's camp] - 알고리즘 대회와 STL (박인서)
[devil's camp] - 알고리즘 대회와 STL (박인서)[devil's camp] - 알고리즘 대회와 STL (박인서)
[devil's camp] - 알고리즘 대회와 STL (박인서)
 
스위프트 성능 이해하기
스위프트 성능 이해하기스위프트 성능 이해하기
스위프트 성능 이해하기
 
C++에서 Objective-C까지
C++에서 Objective-C까지C++에서 Objective-C까지
C++에서 Objective-C까지
 
프로그래밍 대회: C++11 이야기
프로그래밍 대회: C++11 이야기프로그래밍 대회: C++11 이야기
프로그래밍 대회: C++11 이야기
 
8 swift 중첩함수
8 swift 중첩함수8 swift 중첩함수
8 swift 중첩함수
 
C++ 11 에 대해서 쉽게 알아봅시다 1부
C++ 11 에 대해서 쉽게 알아봅시다 1부C++ 11 에 대해서 쉽게 알아봅시다 1부
C++ 11 에 대해서 쉽게 알아봅시다 1부
 
Startup JavaScript 5 - 객체(Date, RegExp, Object, Global)
Startup JavaScript 5 - 객체(Date, RegExp, Object, Global)Startup JavaScript 5 - 객체(Date, RegExp, Object, Global)
Startup JavaScript 5 - 객체(Date, RegExp, Object, Global)
 
자바8강의 2강. Stream API
자바8강의 2강. Stream API자바8강의 2강. Stream API
자바8강의 2강. Stream API
 
Realm.io for iOS
Realm.io for iOSRealm.io for iOS
Realm.io for iOS
 
Do swift: Swift 무작정 해보기
Do swift: Swift 무작정 해보기Do swift: Swift 무작정 해보기
Do swift: Swift 무작정 해보기
 
Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심
 

Viewers also liked

3 swift 컬렉션,흐름제어
3 swift 컬렉션,흐름제어3 swift 컬렉션,흐름제어
3 swift 컬렉션,흐름제어
Changwon National University
 
14 swift 옵셔널체인
14 swift 옵셔널체인14 swift 옵셔널체인
14 swift 옵셔널체인
Changwon National University
 
12 swift 구조체의 변경가능 메소드
12 swift 구조체의 변경가능 메소드12 swift 구조체의 변경가능 메소드
12 swift 구조체의 변경가능 메소드
Changwon National University
 
2 swift 상수,변수,튜풀 옵셔널
2 swift 상수,변수,튜풀 옵셔널2 swift 상수,변수,튜풀 옵셔널
2 swift 상수,변수,튜풀 옵셔널
Changwon National University
 
13 swift 옵셔널
13 swift 옵셔널13 swift 옵셔널
13 swift 옵셔널
Changwon National University
 
20 swift 집합형
20 swift 집합형20 swift 집합형
20 swift 집합형
Changwon National University
 
1 swift소개
1 swift소개1 swift소개
1 swift소개
Changwon National University
 
15 swift 클래스
15 swift 클래스15 swift 클래스
15 swift 클래스
Changwon National University
 
7 swift 제너릭스
7 swift 제너릭스7 swift 제너릭스
7 swift 제너릭스
Changwon National University
 
11 swift 값타입참조타입
11 swift 값타입참조타입11 swift 값타입참조타입
11 swift 값타입참조타입
Changwon National University
 
17 swift 프로토콜
17 swift 프로토콜17 swift 프로토콜
17 swift 프로토콜
Changwon National University
 
10 swift 열거형구조체클래스
10 swift 열거형구조체클래스10 swift 열거형구조체클래스
10 swift 열거형구조체클래스
Changwon National University
 
4 swift 흐름제어
4 swift 흐름제어4 swift 흐름제어
4 swift 흐름제어
Changwon National University
 
30 힙 정렬2 - 최대힙,최소힙,정렬
30 힙 정렬2 - 최대힙,최소힙,정렬30 힙 정렬2 - 최대힙,최소힙,정렬
30 힙 정렬2 - 최대힙,최소힙,정렬
Changwon National University
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
Cihad Horuzoğlu
 

Viewers also liked (15)

3 swift 컬렉션,흐름제어
3 swift 컬렉션,흐름제어3 swift 컬렉션,흐름제어
3 swift 컬렉션,흐름제어
 
14 swift 옵셔널체인
14 swift 옵셔널체인14 swift 옵셔널체인
14 swift 옵셔널체인
 
12 swift 구조체의 변경가능 메소드
12 swift 구조체의 변경가능 메소드12 swift 구조체의 변경가능 메소드
12 swift 구조체의 변경가능 메소드
 
2 swift 상수,변수,튜풀 옵셔널
2 swift 상수,변수,튜풀 옵셔널2 swift 상수,변수,튜풀 옵셔널
2 swift 상수,변수,튜풀 옵셔널
 
13 swift 옵셔널
13 swift 옵셔널13 swift 옵셔널
13 swift 옵셔널
 
20 swift 집합형
20 swift 집합형20 swift 집합형
20 swift 집합형
 
1 swift소개
1 swift소개1 swift소개
1 swift소개
 
15 swift 클래스
15 swift 클래스15 swift 클래스
15 swift 클래스
 
7 swift 제너릭스
7 swift 제너릭스7 swift 제너릭스
7 swift 제너릭스
 
11 swift 값타입참조타입
11 swift 값타입참조타입11 swift 값타입참조타입
11 swift 값타입참조타입
 
17 swift 프로토콜
17 swift 프로토콜17 swift 프로토콜
17 swift 프로토콜
 
10 swift 열거형구조체클래스
10 swift 열거형구조체클래스10 swift 열거형구조체클래스
10 swift 열거형구조체클래스
 
4 swift 흐름제어
4 swift 흐름제어4 swift 흐름제어
4 swift 흐름제어
 
30 힙 정렬2 - 최대힙,최소힙,정렬
30 힙 정렬2 - 최대힙,최소힙,정렬30 힙 정렬2 - 최대힙,최소힙,정렬
30 힙 정렬2 - 최대힙,최소힙,정렬
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
 

Similar to 6 swift 고급함수

C++20 Key Features Summary
C++20 Key Features SummaryC++20 Key Features Summary
C++20 Key Features Summary
Chris Ohk
 
Java jungsuk3 ch14_lambda_stream
Java jungsuk3 ch14_lambda_streamJava jungsuk3 ch14_lambda_stream
Java jungsuk3 ch14_lambda_stream
성 남궁
 
함수적 사고 2장
함수적 사고 2장함수적 사고 2장
함수적 사고 2장
HyeonSeok Choi
 
About Visual C++ 10
About  Visual C++ 10About  Visual C++ 10
About Visual C++ 10
흥배 최
 
[MSP] 카카오 채널 챗봇 개발과 Azure App Service로 배포하기
[MSP] 카카오 채널 챗봇 개발과 Azure App Service로 배포하기[MSP] 카카오 채널 챗봇 개발과 Azure App Service로 배포하기
[MSP] 카카오 채널 챗봇 개발과 Azure App Service로 배포하기
Aron Roh
 
Kakao channel chatbot development & Deploy with azure app service
Kakao channel chatbot development & Deploy with azure app serviceKakao channel chatbot development & Deploy with azure app service
Kakao channel chatbot development & Deploy with azure app service
Aron Roh
 
SpringCamp 2013 : About Jdk8
SpringCamp 2013 : About Jdk8SpringCamp 2013 : About Jdk8
SpringCamp 2013 : About Jdk8Sangmin Lee
 
Functional programming
Functional programmingFunctional programming
Functional programming
ssuserdcfefa
 
Java8 - Oracle Korea Magazine
Java8 - Oracle Korea MagazineJava8 - Oracle Korea Magazine
Java8 - Oracle Korea MagazineJay Lee
 
Kgc2006 Template Metaprogramming을 이용한 LuaTinker 구현
Kgc2006 Template Metaprogramming을 이용한 LuaTinker 구현Kgc2006 Template Metaprogramming을 이용한 LuaTinker 구현
Kgc2006 Template Metaprogramming을 이용한 LuaTinker 구현
Sang Goo Kwon
 
Ch10
Ch10Ch10
Ch10
Hankyo
 
불어오는 변화의 바람, From c++98 to c++11, 14
불어오는 변화의 바람, From c++98 to c++11, 14 불어오는 변화의 바람, From c++98 to c++11, 14
불어오는 변화의 바람, From c++98 to c++11, 14
명신 김
 
Matplotlib 기초 이해하기_20160730
Matplotlib 기초 이해하기_20160730Matplotlib 기초 이해하기_20160730
Matplotlib 기초 이해하기_20160730
Yong Joon Moon
 
[Swift] Functions
[Swift] Functions[Swift] Functions
[Swift] Functions
Bill Kim
 
C++17 Key Features Summary - Ver 2
C++17 Key Features Summary - Ver 2C++17 Key Features Summary - Ver 2
C++17 Key Features Summary - Ver 2
Chris Ohk
 
C++ Template/STL study
C++ Template/STL studyC++ Template/STL study
C++ Template/STL study
Seo Dong-yu
 
//BUILD/ Seoul - .NET의 현재와 미래. 그 새로운 시작
//BUILD/ Seoul - .NET의 현재와 미래. 그 새로운 시작//BUILD/ Seoul - .NET의 현재와 미래. 그 새로운 시작
//BUILD/ Seoul - .NET의 현재와 미래. 그 새로운 시작
Taeyoung Kim
 
Visual studio 2010
Visual studio 2010Visual studio 2010
Visual studio 2010
MinGeun Park
 
파이썬 제대로 활용하기
파이썬 제대로 활용하기파이썬 제대로 활용하기
파이썬 제대로 활용하기
Hansol Kang
 

Similar to 6 swift 고급함수 (20)

C++20 Key Features Summary
C++20 Key Features SummaryC++20 Key Features Summary
C++20 Key Features Summary
 
Java jungsuk3 ch14_lambda_stream
Java jungsuk3 ch14_lambda_streamJava jungsuk3 ch14_lambda_stream
Java jungsuk3 ch14_lambda_stream
 
함수적 사고 2장
함수적 사고 2장함수적 사고 2장
함수적 사고 2장
 
About Visual C++ 10
About  Visual C++ 10About  Visual C++ 10
About Visual C++ 10
 
[MSP] 카카오 채널 챗봇 개발과 Azure App Service로 배포하기
[MSP] 카카오 채널 챗봇 개발과 Azure App Service로 배포하기[MSP] 카카오 채널 챗봇 개발과 Azure App Service로 배포하기
[MSP] 카카오 채널 챗봇 개발과 Azure App Service로 배포하기
 
Kakao channel chatbot development & Deploy with azure app service
Kakao channel chatbot development & Deploy with azure app serviceKakao channel chatbot development & Deploy with azure app service
Kakao channel chatbot development & Deploy with azure app service
 
SpringCamp 2013 : About Jdk8
SpringCamp 2013 : About Jdk8SpringCamp 2013 : About Jdk8
SpringCamp 2013 : About Jdk8
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
Java8 - Oracle Korea Magazine
Java8 - Oracle Korea MagazineJava8 - Oracle Korea Magazine
Java8 - Oracle Korea Magazine
 
Kgc2006 Template Metaprogramming을 이용한 LuaTinker 구현
Kgc2006 Template Metaprogramming을 이용한 LuaTinker 구현Kgc2006 Template Metaprogramming을 이용한 LuaTinker 구현
Kgc2006 Template Metaprogramming을 이용한 LuaTinker 구현
 
Ch10
Ch10Ch10
Ch10
 
불어오는 변화의 바람, From c++98 to c++11, 14
불어오는 변화의 바람, From c++98 to c++11, 14 불어오는 변화의 바람, From c++98 to c++11, 14
불어오는 변화의 바람, From c++98 to c++11, 14
 
Matplotlib 기초 이해하기_20160730
Matplotlib 기초 이해하기_20160730Matplotlib 기초 이해하기_20160730
Matplotlib 기초 이해하기_20160730
 
[Swift] Functions
[Swift] Functions[Swift] Functions
[Swift] Functions
 
C++17 Key Features Summary - Ver 2
C++17 Key Features Summary - Ver 2C++17 Key Features Summary - Ver 2
C++17 Key Features Summary - Ver 2
 
6 function
6 function6 function
6 function
 
C++ Template/STL study
C++ Template/STL studyC++ Template/STL study
C++ Template/STL study
 
//BUILD/ Seoul - .NET의 현재와 미래. 그 새로운 시작
//BUILD/ Seoul - .NET의 현재와 미래. 그 새로운 시작//BUILD/ Seoul - .NET의 현재와 미래. 그 새로운 시작
//BUILD/ Seoul - .NET의 현재와 미래. 그 새로운 시작
 
Visual studio 2010
Visual studio 2010Visual studio 2010
Visual studio 2010
 
파이썬 제대로 활용하기
파이썬 제대로 활용하기파이썬 제대로 활용하기
파이썬 제대로 활용하기
 

More from Changwon National University

생성인공지능둘러보기.pdf
생성인공지능둘러보기.pdf생성인공지능둘러보기.pdf
생성인공지능둘러보기.pdf
Changwon National University
 
2011 app center Changwon National Univ.
2011 app center Changwon National Univ.2011 app center Changwon National Univ.
2011 app center Changwon National Univ.
Changwon National University
 
인공지능의 파도가 온다
인공지능의 파도가 온다인공지능의 파도가 온다
인공지능의 파도가 온다
Changwon National University
 
Mobile Healthcare Application
Mobile Healthcare ApplicationMobile Healthcare Application
Mobile Healthcare Application
Changwon National University
 
바다 즐기기
바다 즐기기바다 즐기기
알아두면 편리한 macOS 에디터 단축키와 기능
알아두면 편리한 macOS 에디터  단축키와 기능알아두면 편리한 macOS 에디터  단축키와 기능
알아두면 편리한 macOS 에디터 단축키와 기능
Changwon National University
 
키보드 기호의 이름 알아보기(한국어, 영어)
키보드 기호의 이름 알아보기(한국어, 영어)키보드 기호의 이름 알아보기(한국어, 영어)
키보드 기호의 이름 알아보기(한국어, 영어)
Changwon National University
 
AI 로봇 아티스트의 비밀(창원대학교 정보통신공학과 특강)
AI 로봇 아티스트의 비밀(창원대학교 정보통신공학과 특강)AI 로봇 아티스트의 비밀(창원대학교 정보통신공학과 특강)
AI 로봇 아티스트의 비밀(창원대학교 정보통신공학과 특강)
Changwon National University
 
20 2 강의를 마치며
20 2 강의를 마치며20 2 강의를 마치며
20 2 강의를 마치며
Changwon National University
 
20 1 코딩스타일
20 1 코딩스타일20 1 코딩스타일
20 1 코딩스타일
Changwon National University
 
18 2 파이썬표준라이브러리
18 2 파이썬표준라이브러리18 2 파이썬표준라이브러리
18 2 파이썬표준라이브러리
Changwon National University
 
18 1 파이썬패키지
18 1 파이썬패키지18 1 파이썬패키지
18 1 파이썬패키지
Changwon National University
 
17 2 필터함수와 맵함수
17 2 필터함수와 맵함수17 2 필터함수와 맵함수
17 2 필터함수와 맵함수
Changwon National University
 
17 1 람다함수
17 1 람다함수17 1 람다함수
17 1 람다함수
Changwon National University
 
16 1 상속과super()
16 1 상속과super()16 1 상속과super()
16 1 상속과super()
Changwon National University
 
15 2 클래스정의와self
15 2 클래스정의와self15 2 클래스정의와self
15 2 클래스정의와self
Changwon National University
 
14 4 슬라이싱
14 4 슬라이싱14 4 슬라이싱
14 4 슬라이싱
Changwon National University
 
14 2 iterator
14 2 iterator14 2 iterator
14 3 리스트함수
14 3 리스트함수14 3 리스트함수
14 3 리스트함수
Changwon National University
 
14 1 리스트의 메소드
14 1 리스트의 메소드14 1 리스트의 메소드
14 1 리스트의 메소드
Changwon National University
 

More from Changwon National University (20)

생성인공지능둘러보기.pdf
생성인공지능둘러보기.pdf생성인공지능둘러보기.pdf
생성인공지능둘러보기.pdf
 
2011 app center Changwon National Univ.
2011 app center Changwon National Univ.2011 app center Changwon National Univ.
2011 app center Changwon National Univ.
 
인공지능의 파도가 온다
인공지능의 파도가 온다인공지능의 파도가 온다
인공지능의 파도가 온다
 
Mobile Healthcare Application
Mobile Healthcare ApplicationMobile Healthcare Application
Mobile Healthcare Application
 
바다 즐기기
바다 즐기기바다 즐기기
바다 즐기기
 
알아두면 편리한 macOS 에디터 단축키와 기능
알아두면 편리한 macOS 에디터  단축키와 기능알아두면 편리한 macOS 에디터  단축키와 기능
알아두면 편리한 macOS 에디터 단축키와 기능
 
키보드 기호의 이름 알아보기(한국어, 영어)
키보드 기호의 이름 알아보기(한국어, 영어)키보드 기호의 이름 알아보기(한국어, 영어)
키보드 기호의 이름 알아보기(한국어, 영어)
 
AI 로봇 아티스트의 비밀(창원대학교 정보통신공학과 특강)
AI 로봇 아티스트의 비밀(창원대학교 정보통신공학과 특강)AI 로봇 아티스트의 비밀(창원대학교 정보통신공학과 특강)
AI 로봇 아티스트의 비밀(창원대학교 정보통신공학과 특강)
 
20 2 강의를 마치며
20 2 강의를 마치며20 2 강의를 마치며
20 2 강의를 마치며
 
20 1 코딩스타일
20 1 코딩스타일20 1 코딩스타일
20 1 코딩스타일
 
18 2 파이썬표준라이브러리
18 2 파이썬표준라이브러리18 2 파이썬표준라이브러리
18 2 파이썬표준라이브러리
 
18 1 파이썬패키지
18 1 파이썬패키지18 1 파이썬패키지
18 1 파이썬패키지
 
17 2 필터함수와 맵함수
17 2 필터함수와 맵함수17 2 필터함수와 맵함수
17 2 필터함수와 맵함수
 
17 1 람다함수
17 1 람다함수17 1 람다함수
17 1 람다함수
 
16 1 상속과super()
16 1 상속과super()16 1 상속과super()
16 1 상속과super()
 
15 2 클래스정의와self
15 2 클래스정의와self15 2 클래스정의와self
15 2 클래스정의와self
 
14 4 슬라이싱
14 4 슬라이싱14 4 슬라이싱
14 4 슬라이싱
 
14 2 iterator
14 2 iterator14 2 iterator
14 2 iterator
 
14 3 리스트함수
14 3 리스트함수14 3 리스트함수
14 3 리스트함수
 
14 1 리스트의 메소드
14 1 리스트의 메소드14 1 리스트의 메소드
14 1 리스트의 메소드
 

6 swift 고급함수

  • 1. 6. Swift 기초 - 고급 함수 창원대학교 정보통신공학과 박동규 2015. 12
  • 2. 함수 레이블 • Swift에서 두개 이상의 매개변수를 가진 함수를 호출할 때는 반드시 두번째 매개변수부터 레이블을 적어주어야 한다( Swift 2.0 이후 ) • 레이블은 매개변수의 목적이나 기능을 명시하여 코드를 더 읽기 쉽게 만들고 에러를 줄이는데 도움이 된다
  • 5. 함수 레이블 vs join 함수를 통해 매개변수로 입력된 String을 조합할 수 있다 매개변수가 2개 이상이면 두번째 매개변수는 반드시 레이블링을 해야한다. 레이블링을 통해 매개변수의 역할을 명확하게 이해할 수 있다. Objective-C와의 호환성을 확보할 수 있다
  • 6. 함수 레이블 vs join 함수를 통해 매개변수로 입력된 String을 조합할 수 있다 매개변수가 2개 이상이면 두번째 매개변수는 반드시 레이블링을 해야한다. 레이블링을 통해 매개변수의 역할을 명확하게 이해할 수 있다. Objective-C와의 호환성을 확보할 수 있다
  • 7. 함수 레이블 vs join 함수를 통해 매개변수로 입력된 String을 조합할 수 있다 매개변수가 2개 이상이면 두번째 매개변수는 반드시 레이블링을 해야한다. 레이블링을 통해 매개변수의 역할을 명확하게 이해할 수 있다. Objective-C와의 호환성을 확보할 수 있다
  • 8. 가변인자(variadic) 함수 • 함수구문에서 함수에 전달되는 매개변수의 수를 정확하 게 알 수 없을 경우에 사용하는 문법으로 ... 으로 표시
  • 9. 가변인자(variadic) 함수 • 함수구문에서 함수에 전달되는 매개변수의 수를 정확하 게 알 수 없을 경우에 사용하는 문법으로 ... 으로 표시
  • 10. 함수 타입(형) (Int, Int) 타입 매개변수를 입력으로 받아서 Int형 값을 반환하는 함수임
  • 11. 함수 타입 • 함수타입(형)의 상수나 변수를 만들어 함수를 할당할 (assign) 수 있음 두 개의 Int 값을 매개변수로 취하며 Int 값을 반환하는 함수타입(형) 변수 mathFuntion을 선언하고, 이 변수가 addTwoInts 함수를 참조(refer) 하도록 한다.
  • 14. 함수 타입 함수 타입 변수 mathFunction
  • 15. 함수 타입 Result: 5 함수 타입 변수 mathFunction
  • 18. C 언어의 함수 포인터
  • 19. C 언어의 함수 포인터 mathFunction, newMathFunction은 함수의 주소를 담을 수 있는 변수 -> 함수 포인터
  • 20. C 언어의 함수 포인터 … int addTwoInts(int a, int b) { return a + b; } int main(int argc, const char * argv[]) { int (*mathFunction)(int, int) = &addTwoInts; int (*newMathFunction)(int, int); newMathFunction = mathFunction; …
  • 21. C 언어의 함수 포인터 … int addTwoInts(int a, int b) { return a + b; } int main(int argc, const char * argv[]) { int (*mathFunction)(int, int) = &addTwoInts; int (*newMathFunction)(int, int); newMathFunction = mathFunction; …
  • 22. C 언어의 함수 포인터 … int addTwoInts(int a, int b) { return a + b; } int main(int argc, const char * argv[]) { int (*mathFunction)(int, int) = &addTwoInts; int (*newMathFunction)(int, int); newMathFunction = mathFunction; … C 언어의 함수
  • 23. C 언어의 함수 포인터 … int addTwoInts(int a, int b) { return a + b; } int main(int argc, const char * argv[]) { int (*mathFunction)(int, int) = &addTwoInts; int (*newMathFunction)(int, int); newMathFunction = mathFunction; … C 언어의 함수
  • 24. C 언어의 함수 포인터 … int addTwoInts(int a, int b) { return a + b; } int main(int argc, const char * argv[]) { int (*mathFunction)(int, int) = &addTwoInts; int (*newMathFunction)(int, int); newMathFunction = mathFunction; …
  • 25. C 언어의 함수 포인터 … int addTwoInts(int a, int b) { return a + b; } int main(int argc, const char * argv[]) { int (*mathFunction)(int, int) = &addTwoInts; int (*newMathFunction)(int, int); newMathFunction = mathFunction; …
  • 26. C 언어의 함수 포인터 … int addTwoInts(int a, int b) { return a + b; } int main(int argc, const char * argv[]) { int (*mathFunction)(int, int) = &addTwoInts; int (*newMathFunction)(int, int); newMathFunction = mathFunction; … 함수 포인터
  • 27. C 언어의 함수 포인터 … int addTwoInts(int a, int b) { return a + b; } int main(int argc, const char * argv[]) { int (*mathFunction)(int, int) = &addTwoInts; int (*newMathFunction)(int, int); newMathFunction = mathFunction; … 함수 포인터
  • 28. C 언어의 함수 포인터 … int addTwoInts(int a, int b) { return a + b; } int main(int argc, const char * argv[]) { int (*mathFunction)(int, int) = &addTwoInts; int (*newMathFunction)(int, int); newMathFunction = mathFunction; …
  • 29. C 언어의 함수 포인터 … int addTwoInts(int a, int b) { return a + b; } int main(int argc, const char * argv[]) { int (*mathFunction)(int, int) = &addTwoInts; int (*newMathFunction)(int, int); newMathFunction = mathFunction; …
  • 30. C 언어의 함수 포인터 … int addTwoInts(int a, int b) { return a + b; } int main(int argc, const char * argv[]) { int (*mathFunction)(int, int) = &addTwoInts; int (*newMathFunction)(int, int); newMathFunction = mathFunction; … 함수 포인터
  • 31. C 언어의 함수 포인터 … int addTwoInts(int a, int b) { return a + b; } int main(int argc, const char * argv[]) { int (*mathFunction)(int, int) = &addTwoInts; int (*newMathFunction)(int, int); newMathFunction = mathFunction; … 함수 포인터
  • 32. C 언어의 함수 포인터 … int addTwoInts(int a, int b) { return a + b; } int main(int argc, const char * argv[]) { int (*mathFunction)(int, int) = &addTwoInts; int (*newMathFunction)(int, int); newMathFunction = mathFunction; …
  • 33. C 언어의 함수 포인터 … int addTwoInts(int a, int b) { return a + b; } int main(int argc, const char * argv[]) { int (*mathFunction)(int, int) = &addTwoInts; int (*newMathFunction)(int, int); newMathFunction = mathFunction; …
  • 34. C 언어의 함수 포인터 … int addTwoInts(int a, int b) { return a + b; } int main(int argc, const char * argv[]) { int (*mathFunction)(int, int) = &addTwoInts; int (*newMathFunction)(int, int); newMathFunction = mathFunction; … 함수 포인터를 다른 함수 포인터에 복사할 수 있음
  • 39. 함수의 반환 Int형 값을 매개변수로 받아 Int 값을 반환하는 함수
  • 40. 함수의 반환 Int형 값을 매개변수로 받아 Int 값을 반환하는 함수 Int형 값을 매개변수로 받아 Int 값을 반환하는 함수
  • 41. 함수의 반환 Int형 값을 매개변수로 받아 Int 값을 반환하는 함수 Int형 값을 매개변수로 받아 Int 값을 반환하는 함수
  • 42. 함수의 반환 반환형- Int형을 매개변수로 받아 Int 값을 반환하는 함수 Int형 값을 매개변수로 받아 Int 값을 반환하는 함수 Int형 값을 매개변수로 받아 Int 값을 반환하는 함수
  • 43. 함수의 반환 반환형- Int형을 매개변수로 받아 Int 값을 반환하는 함수 Int형 값을 매개변수로 받아 Int 값을 반환하는 함수 Int형 값을 매개변수로 받아 Int 값을 반환하는 함수
  • 44. 함수의 반환 반환형- Int형을 매개변수로 받아 Int 값을 반환하는 함수 Int형 값을 매개변수로 받아 Int 값을 반환하는 함수 Int형 값을 매개변수로 받아 Int 값을 반환하는 함수
  • 45. 함수의 반환 매개변수 backwards가 true이면 stepBackward 함 수를, false이면 stepForward 함수를 반환한다 반환형- Int형을 매개변수로 받아 Int 값을 반환하는 함수 Int형 값을 매개변수로 받아 Int 값을 반환하는 함수 Int형 값을 매개변수로 받아 Int 값을 반환하는 함수
  • 46. 중첩 함수 • 함수 내부에 다른 함수를 중첩할 수 있다
  • 47. 중첩 함수 • 함수 내부에 다른 함수를 중첩할 수 있다
  • 48. 중첩 함수 • 함수 내부에 다른 함수를 중첩할 수 있다 반환형은 Int를 매개변수로 받아 Int형
  • 49. 중첩 함수 • 함수 내부에 다른 함수를 중첩할 수 있다 반환형은 Int를 매개변수로 받아 Int형 값을 반환하는 함수
  • 50. 정리 • 함수의 매개변수가 가변적일 경우 - variadic 문법 • 함수형의 상수나 변수를 만들어 함수를 할당할 수 있음 • 중첩함수를 만들 수 있음 • 함수 내부에서 정의한 함수형을 반환할 수 있음 • C의 함수 포인터보다 간단하면서도 강력한 기능