Skip to content

Instantly share code, notes, and snippets.

@euskadi31
Last active Jun 8, 2016
Embed
What would you like to do?
[swift-evolution] custom attribute in userland.
// Example of custom attribute
@attribute("route")
struct Route {
var route: String
var name: String?
init(route: String) {
self.route = route
}
}
@attribute("method")
struct Method {
var verb: String
init(verb: String) {
self.verb = verb
}
}
struct CourseController {
@route("/courses/", name="toto")
@method("GET")
func listAction(request: Request) -> Response {
return Response(200, "Hello World")
}
}
let app = Application()
app.register(CourseController())
app.run(8080)
// other example of custom attribute
@mappable
class ArticleEntity {
@field("article_id")
var id: Int
@field("article_name")
var name: String
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment