【问题标题】:Xcode beta 7 - Do-While loop SWIFT ErrorXcode beta 7 - Do-While 循环 SWIFT 错误
【发布时间】:2015-09-25 01:43:14
【问题描述】:

以下代码给出了错误

“do-while”循环中的预期“while”

if let path = NSBundle.mainBundle().pathForResource("Chapters", ofType: "txt"){
do {
    let stringFromFile = try String(contentsOfFile:path, encoding: NSUTF8StringEncoding)
    var chapters: [String] = stringFromFile.componentsSeparatedByString("@")
    chapters.removeAtIndex(0)
} catch {
    print((error))
  }
}

它之前工作正常,但现在它给了我一个错误。有谁知道为什么?

【问题讨论】:

    标签: xcode swift do-while xcode7 do-loops


    【解决方案1】:

    该代码在 Playground 中对我有效,在 Resources 文件夹中具有相应的 Chapters.txt 文件; XCode 7.1 构建 7B60。您是否尝试过使用 Shift-Command-K 进行干净构建?

    您的错误消息似乎有些不对劲。在 Swift 2.0 中,不再有 do-while 循环。它们已被 repeat-while 循环取代。正如您的代码 sn-p 所示,do 已重新用于do-try-catch 错误处理。

    【讨论】:

    • 傻我。嗯。这是一个错误,因为我在旧版本 od xCode 中启动
    猜你喜欢
    • 2014-10-29
    • 2016-07-30
    • 2023-03-18
    • 1970-01-01
    • 2015-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-09
    相关资源
    最近更新 更多