izqui / Taylor

A lightweight library for writing HTTP web servers with Swift
MIT License
926 stars 79 forks source link

Argument number mismatch in demo code? #35

Closed simonprickett closed 8 years ago

simonprickett commented 8 years ago

I'm new to both Swift coding and Taylor, been trying to get the example program to run and I keep getting:

server.swift:6:2: error: contextual type for closure argument list expects 3 arguments, but 2 were specified
        req, res in

with my code being:

import Taylor

let server = Taylor.Server()

server.get("/") { 
    req, res in
    res.bodyString = "Hello, world!"
    return .Send
}

let port = 3000
do {
    print("Starting server on port: \(port)")
    try server.serveHTTP(port: port, forever: true)
} catch {
    print("Server start failed \(error)")
}

Just wondering what I'm doing wrong here, I can't work out what any missing parameter would be from reading the Taylor source code right now.

Danappelxx commented 8 years ago

Ah - sorry for the confusion. We haven't had the chance to tag a release for the new usage, but already updated the README. You have two options: 1) Update your version of Taylor by adding either "master" to the end of the line of your Cartfile, or adding :branch => "master" in your Podfile, depending on which one you're using. 2) Use the old usage, which is actually:

server.get("/") { req, res, cb in
  // ...
  cb(.Send(req, res))
}

but I wouldn't bother with it since a new release will be tagged asap.

Sorry for the inconvenience.

simonprickett commented 8 years ago

No problem, thanks for clarifying I'll go with the master option in the Cartfile. - working great now.