Dimitri T
Dimitri T

Reputation: 951

xcode error 'consecutive statements on a line must be separated by' when creating endpoint URL for REST API datatask

I am a beginner, trying to code a POST datarequest to post a vote to the 'rating' field of a Drupalnode (so that users can rate movies). I have followed online guides, carefully copying the syntax, but in Xcode am receiving this error for for this line: let movieEndpoint: String = https://www.examplesitename.com/film1 The red error message is "consecutive statements on a line must be separated by a ';' The error highlights the ':' after https, and suggests "fix it" with an ';' but changing it to https;www.examplesitename.com/film1 then brings up another red error 'expected expression' (and doesn't seem correct as it is a URL)

For context, below is my code, (which I hope will work to post my data request but haven't been able to check yet)

 let config = NSURLSessionConfiguration.defaultSessionConfiguration()
    let session = NSURLSession(configuration: config)

    let movieEndpoint: String = https://www.sitename.com/film1
    guard let movieURL = NSURL(string: movieEndpoint) else {
        print("Error: cannot create URL")
        return
    }

    let movieUrlRequest = NSMutableURLRequest(URL: movieURL)
    movieUrlRequest.HTTPMethod = "POST"

    let task = session.dataTaskWithRequest(movieUrlRequest, completionHandler:{ _, _, _ in })

    let newRating = ["rating": 50, "userId": 1,]
    let jsonRating: NSData
    do {
        jsonRating = try NSJSONSerialization.dataWithJSONObject(newRating, options: [])
        movieUrlRequest.HTTPBody = jsonRating
    } catch {
        print("Error: cannot create JSON from todo")
        return
    }
    movieUrlRequest.HTTPBody = jsonRating

    task.resume()

}

Thank you for any help you can give me.

Upvotes: 1

Views: 2099

Answers (1)

Gustanas
Gustanas

Reputation: 416

The proper way to declare a String in Swift is to add " " around the string.

Fix your code like this:

let movieEndpoint: String = "https://www.sitename.com/film1"

Upvotes: 1

Related Questions