的值。它是tableViewController的位置名稱列表。 無法投類型的值 '__NSCFArray'(0x1039adae0)到 '的NSString'(0x10301db00),在使用的plist請幫助。不能投出
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()
}
我不知道我有什麼回報
(
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Return the number of rows in the section.
return 10
}
如果'locationArray'確實是一個數組,那麼不要像字典那樣訂閱它......如果'locationArray'是一個字典,但是它是一個數組,那麼''locationArray [「name」]'可以工作。首先重構關於這部分的代碼。 – Moritz
@EricD。有我的Location.plist http://s020.radikal.ru/i718/1510/52/6cc3f4863e80.png我不明白什麼是錯的是在代碼 – Diana