함수를 사용하면 다음과 같은 이점이 있다.
- 동일한 코드가 여러곳에서 사용될 때 함수를 사용하면
재작성
할 필요가 없어진다.
- 전체 프로세스를 하나의 소스코드에서 연속적으로 작성하는 것 보다는,
기능 단위
로 함수화 하면 가독성이 좋아지고, 로직을 이해하기 쉽다.
- 비지니스 로직을 변경할 때 함수 내부만 수정하면 되므로,
유지보수
에 용이하다.
1. 함수의 정의와 호출(Defining and Calling Functions)
선언시 func
키워드를 붙이고 Argument
와 Parameter
(named person: String) 를 정의한 뒤, ->String
형태로 반환형을 정의한다.

2. 함수 파라미터와 반환 값 (Function Parameters and Return Values)
파라미터가 없는 함수 (Functions Without Parameters)

복수의 파라미터를 사용하는 함수 (Functions With Multiple Parameters)

반환 값이 없는 함수 (Functions Without Return Values)

복수의 값을 반환하는 함수 (Functions with Multiple Return Values)

옵셔널 튜플 반환형 (Optional Tuple Return Types)

함수 인자 라벨과 파라미터 이름 (Function Argument Labels and Parameter Names)

인자 라벨 지정 (Specifying Argument Labels)
코드를 더 Readable하게 만들어주기 위해 인자(Argument)를 사용할 수 있다.

인자 생략 (Omitting Argument Labels)

기본 파라미터 값 (Default Parameter Values)

집합 파라미터 (Variadic Parameters)

인-아웃 파라미터 (In-Out Parameters)
인자 값을 직접 변경하는 파라미터로 inout
키워드를 사용한다.
포인터를 넣는 것과 비슷한 개념으로 &
키워드를 사용한다.
