gpt4 book ai didi

Xcode beta 7 - Do-While 循环 SWIFT 错误

转载 作者:可可西里 更新时间:2023-11-01 02:19:00 28 4
gpt4 key购买 nike

下面的代码给出了错误

Expected 'while' in 'do-while' loop

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

之前是正常的,现在报错了。有谁知道为什么吗?

最佳答案

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

enter image description here

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

关于Xcode beta 7 - Do-While 循环 SWIFT 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32773501/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com