TIL how to use `do` block in Swift to narrow scope of vars inside block
TIL how to use do
block in Swift just how usually {}
is used in C to narrow vars scope. Following snippet is take from PR in Vapor:
do {
let foo = "foo"
let uri: URI = "/\(foo)/bar/baz"
XCTAssertEqual(uri.path, "/foo/bar/baz")
}
do {
let uri = URI(scheme: "foo", host: "host", port: 1, path: "test", query: "query", fragment: "fragment")
XCTAssertEqual(uri.string, "foo://host:1/test?query#fragment")
}