Skip to content

Instantly share code, notes, and snippets.

@euskadi31
Last active June 8, 2016 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save euskadi31/2e15d21bc718b6f02f3497ad3e0a531d to your computer and use it in GitHub Desktop.
Save euskadi31/2e15d21bc718b6f02f3497ad3e0a531d to your computer and use it in GitHub Desktop.
[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