2

The following code gives the error

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

it was working fine before, but now it's giving me an error. Does anyone know why?

ScarletEnvy
  • 871
  • 1
  • 7
  • 14

1 Answers1

1

That code works for me as-is in the Playground with the appropriate Chapters.txt file in the Resources folder; XCode 7.1 Build 7B60. Did you try Shift-Command-K for a Clean Build?

enter image description here

Something does not seem right with your error message. With Swift 2.0, there are no more do-while loops. They have been replaced by repeat-while loops instead. As your code snippet shows, do has been repurposed for do-try-catch error handling.

Price Ringo
  • 3,424
  • 1
  • 19
  • 33