Swift 2.0 - 无法下标'[CLPlacemark]类型的值?

Ren*_*pão 0 xcode7 swift2

我正在尝试将我的swift 1.2应用程序转换为2.0.我尝试了一些我在互联网上找到的修复程序,但它不起作用.

错误: Converting to Swift 2.0 - Cannot Subscript a value of type '[CLPlacemark]?'

码:

 func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{

    CLGeocoder().reverseGeocodeLocation(manager.location!, completionHandler: {(placemarks, error)->Void in

        if (error != nil)
        {
            print("Error: " + error!.localizedDescription)
            return
        }

        if placemarks!.count > 0
        {
            let pm = placemarks[0] as! CLPlacemark
            self.displayLocationInfo(pm)
        }
        else
        {
            print("Error with the data.")
        }
    })
}
Run Code Online (Sandbox Code Playgroud)

Ren*_*pão 5

解决:

更换: let pm = placemarks[0] as! CLPlacemark

对于: let pm = placemarks?[0]