拜托,help.Could 不要转换类型的值

Please,help.Could not cast value of type

它是带有位置名称列表的 tableViewController。 当我使用 plist

时,无法将类型 '__NSCFArray' (0x1039adae0) 的值转换为 'NSString' (0x10301db00)。
 import UIKit
    class LocationsTableViewController: UITableViewController {

let location = LocationsClass()
override func viewDidLoad()
{
    super.viewDidLoad()

    let locationsPath = NSBundle.mainBundle().pathForResource("Location", ofType: "plist")
    let locationsArray = NSArray(contentsOfFile:locationsPath!)!
    let stationsPath = NSBundle.mainBundle().pathForResource("Station", ofType: "plist")
    let stationsDict = NSDictionary(contentsOfFile: stationsPath!)!

    for locationArray in locationsArray
    {
There is a mistake in the following line
        location.name = locationArray["name"] as! String//Could not assign a value of type AnyObject?! to a value of type String 
        location.image = locationArray["image"] as! String



let stationsArray = stationsDict[location.name as String] as! NSArray
            for stationArray in stationsArray {

                let dictionaryFromArray = stationArray as! NSDictionary
                let workObject = StationsClass(nameStation:dictionaryFromArray["nameStatiom"] as! String, address: dictionaryFromArray["address"] as! String)

            location.stations.append(workObject)

        }
        }
    }

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()

    }

我不知道,什么 return

( 
      override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            // Return the number of rows in the section.

            return 10

        }

您的 locationArray 数组包含一个字典。该字典有一个键 "name",其中包含一个字符串数组。

忘掉你的 for locationArray in locationsArray 循环,使用 [0] 从数组中提取第一个(也是唯一的)项,然后将其转换为 if let 的字典,如下所示:

if let dict = locationArray[0] as? [String:AnyObject] {

}

然后您可以在里面访问 "name" 键的值并将其转换为字符串数组:

if let dict = locationArray[0] as? [String:AnyObject] {
    if let namesArray = dict["name"] as? [String] {

    }
}

最后你可以获得你的值:

if let dict = locationArray[0] as? [String:AnyObject] {
    if let namesArray = dict["name"] as? [String] {
        for name in namesArray {
            print(name)
        }
    }
}