Parameters after opening bracket

后端 未结 1 1251
灰色年华
灰色年华 2020-12-11 10:44

I am doing my first steps in Vapor, the web framework for Swift.

The first piece of code that called my attention was this:

app.get(\"welcome\") { re         


        
相关标签:
1条回答
  • 2020-12-11 11:21

    This is called trailing closure syntax.

    I give a nice rundown of the various syntactic sugars of closures in this answer.

    The expanded version of this code would be:

    app.get("welcome", { (request: Request) throws -> ResponseRepresentable in 
        return "Hello"
    })
    
    0 讨论(0)
提交回复
热议问题