由于从Swift 2到Swift 3的过渡发生了变化,我无法找到Xcode上代码问题的解决方案。
func addBuildingPins(){
let filePath = Bundle.main.path(forResource: "CurtinBuildingList", ofType: "plist")
let buildings = NSMutableArray(contentsOfFile: (filePath)!) /*check plist file to see if it is a dictionary or array or else for loop cannot run*/
for building in buildings!{
let point = CGPointFromString(building["coordinate"] as! String)
let coordinate = CLLocationCoordinate2DMake(CLLocationDegrees(point.x), CLLocationDegrees(point.y))
let title = building["title"] as! String
let typeRawValue = Int(building["type"] as! String)!
let type = BuildingType(rawValue: typeRawValue)
let subtitle = building["subtitle"] as! String
let annotation = BuildingAnnotation(coordinate: coordinate, title: title, subtitle: subtitle, type: type!)
mapView.addAnnotation(annotation)
print(building)
}
}
错误就在方括号(building [])之前。我一直得到的错误是
输入'NSFastEnumerationIterator.Element'(又名,Any)没有下标成员“。
有什么方法吗?
答案 0 :(得分:1)
在使用for循环之前,将buildings数组转换为[[String: Any]]
。
if let array = buildings as? [[String: Any]] {
for building in array {
//Your code
}
}