swift - 为 REST API datatask 创建端点 URL 时出现 xcode 错误 'consecutive statements on a line must be separated by'

标签 swift compiler-errors xcode7.3

我是一个初学者,正在尝试编写一个 POST 数据请求来向 Drupalnode 的“评级”字段发布投票(以便用户可以对电影进行评级)。我已遵循在线指南,仔细复制语法,但在 Xcode 中,我收到此行的错误: 让 movieEndpoint: 字符串 = https://www.examplesitename.com/film1 红色错误消息是“一行中的连续语句必须用‘;’分隔 该错误突出显示 https 后面的“:”,并建议使用“;”“修复它”但将其更改为 https;www.examplesitename.com/film1 然后会出现另一个红色错误“预期表达式”(并且似乎不正确,因为它是 URL)

对于上下文,下面是我的代码(我希望它能够发布我的数据请求,但尚未能够检查)

 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()

}

感谢您为我提供的任何帮助。

最佳答案

在 Swift 中声明字符串的正确方法是在字符串周围添加“”。

像这样修复你的代码:

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

关于swift - 为 REST API datatask 创建端点 URL 时出现 xcode 错误 'consecutive statements on a line must be separated by',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36907857/

相关文章:

macos - Swift 中的 OS X 应用程序 View 管理

ios - 处理背靠背 HTTP 帖子 SWIFT 4.0

C++ 编译错误 : ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

swift - 使用 Slather 的代码覆盖率报告

xcode - Xcode 8 升级后恢复 Xcode 7.3.1

iOS 10 : NSInvalidLayoutConstraintException: Constraint improperly relates anchors of incompatible types

ios - 更改了子字符串的颜色,但字体设置已重置

c++ - bad_alloc 标识符无法识别?

compilation - VHDL编译错误

swift - 如何更改 searchController?.searchBar 的大小和位置?