filesystem
-
Swift Tips & Tricks - deferSwift/Tips & Tricks 2021. 9. 14. 13:36
Swift 에 defer 라는 keyword 가 있다. 사전적 의미는 연기하다, Xcode 내 의미는 Excutes a set of statements before execution leaves the current block of code. 즉, defer 가 속해있는 block 이 나가기 전에 (block 이 끝 라인까지 읽혀서 끝나거나, 중간에 guard let 등으로 코드를 벗어나게 될 때) 실행된다. 아래는 youtube 에서 가져온 예제 소스이다. func useFile() { let file = try! FileHandle(forReadingFrom: URL(string: "~/temp.txt")!) guard let data = try? file.readToEnd() else { retur..