본문 바로가기

IOS

[Swift] 낯선 개념: $0의 의미

$0 is a shortcut to mean "first argument" in a closure.

클로저에서 첫번째 인수를 의미하는 약식어 정도 생각하면 될 것 같다.

클로저는 이름 없는 함수를 의미한다. 예를 들어보면 아래와 같다.

let nums = [1,62,33,34]
nums.forEach { print($0) }


//출력 결과
1
62
33
34

https://ideone.com/8Dm42C

 

참고자료

https://developer.apple.com/forums/thread/124678

 

 

What is the '$0' syntax in Swift | Apple Developer Forums

I had a question about the $0 syntax in Swift. Haven't had a chance to use it much, however, I am working with things like filter, flatmap, and compactmap, so I see them more often. Any documentation reference or resources on these topics would be super he

developer.apple.com