.
A defer statement is used for executing code just before transferring program control outside of the scope that the defer statement appears in.
1 | defer { |
1 | “func f() { |
Alamofire
中用defer来确保get和set中的操作能线程安全
1 | subscript(task: URLSessionTask) -> Request? { |
defer 的 block 执行顺序和书写的顺序是相反的,这种相反的顺序是必要的,是为了确保每样东西的 defer block 在被创建的时候,该元素依然在当前上下文中存在。