-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
defer란 무엇인지 설명하시오. #25
Labels
Swift
Swift CS 개념 공부
Comments
defer란 무엇인지 설명하시오.Defer Statement
defer {
<#statements#>
}
func sayNumber() {
defer {
print("print check : 1")
}
print("print check : 2")
}
//print check : 2
//print check : 1
func sayCheckNumber() {
defer {
for i in 0..<5 {
print("for loop check : \(i)")
}
}
print("print check : 5")
}
// print check : 5
// for loop check : 0
// for loop check : 1
// for loop check : 2
// for loop check : 3
// for loop check : 4
func sayNestedNumber() {
defer {
print("print check : 1")
}
defer {
print("print check : 2")
}
defer {
print("print check : 3")
}
print("print check : 4")
}
// print check : 4
// print check : 3
// print check : 2
// print check : 1 Defer 호출 되지 않는 경우
Defer를 사용하는 경우
📝 참고 사이트 |
defer란?
defer {
//statements
} defer가 사용되는 곳
출처 |
defer란블록 내에서 작성된 위치에 상관없이 함수 종료시점에 실행되도록 하는 클로저이다. func ...() {
defer {
print("world")
}
print("hello")
}
// 결과
// hello
// world 📝 참고 사이트 |
defer 란
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: