Swift数组,文本文件?

Swift Array, TextFile?

我有一个表视图,它显示从一个表视图到另一个表视图的以下导航:

这是使用以下代码完成的:

 if var path = NSBundle.mainBundle().pathForResource("Chapters", ofType: "txt"){
         var data = String(contentsOfFile:path, encoding: NSUTF8StringEncoding, error: nil)
         if var content = (data){

             //Breaks the entire String into individual strings at each newLine
             var line: [String] = content.componentsSeparatedByCharactersInSet(NSCharacterSet.newlineCharacterSet())

             //First Table - Displays Chapters
             var lineArray = [line[0],
                              line[6],
                              line[12]]

我怎样才能让它改为阅读此内容?

主题:食物、颜色、动物、汽车//each as a separate string. 如果我使用它,它会将整行显示为从 "Topics: ...." 开始的文本所以基本上我要问的是,有没有办法阅读过去的主题,并且只需在 Food 开始第一个字符串 [0] ?

我不知道我是否理解你的问题,但我想你想从字符串 Topics: Food, Water, Melon, Car 中跳过 topics: ......所以在分开你想要的字符串之后索引 0...

  var str = "Topics: Food, color, animals, cars"

  // Get location of first Space or any character you want
  let loc = find(str, " ")

  //Get the string from first space to end of string     
  let skipstr = Range(start: loc!,
            end: str.endIndex)
  let finalStr = str.substringWithRange(skipstr)

  println(finalStr)  
  //Output:-->  Food, color, animals, cars

然后将字符串与逗号分开

 let indexes = finalStr.componentsSeparatedByString(",")
 println(indexes[0])
 //And you got Food at index 0