日記
今日書いたコード
var customersInLine = ["Chris", "Alex", "Ewa", "Barry", "Daniella"] func serve(customer customerProvider: @autoclosure () -> String) { print("Now serving \(customerProvider())!") } serve(customer: customersInLine.remove(at: 0))
初めて知ったこと
Autoclosures自体初めて知ったが使い所がわからない.標準ライブラリのassert(_ condition:,_ message:)
はdebugビルドのときだけcondition
が実行されるが,これはAuclosuresを使って実装されている.
public func assert(_ condition: @autoclosure () -> Bool, _ message: @autoclosure () -> String = String(), file: StaticString = #file, line: UInt = #line)