我在将 Swift 1.2 代码转换为 2.0 时遇到了一些问题——这就是其中之一。
我有一个功能,它可以打开 iOS 地图应用程序来指示一个位置。在转换之前它工作正常。现在我收到以下错误消息:
Cannot invoke 'openMapsWithItems' with an argument list of type '([MKMapItem], launchOptions: [NSObject : AnyObject])'
这是我的代码(错误出现在最后一行):
func openMapsWithDirections(longitude:Double, latitude:Double, placeName:String){
var coordinate = CLLocationCoordinate2DMake(CLLocationDegrees(longitude), CLLocationDegrees(latitude))
var placemark:MKPlacemark = MKPlacemark(coordinate: coordinate, addressDictionary:nil)
var mapItem:MKMapItem = MKMapItem(placemark: placemark)
mapItem.name = placeName
let launchOptions:NSDictionary = NSDictionary(object: MKLaunchOptionsDirectionsModeDriving, forKey: MKLaunchOptionsDirectionsModeKey)
var currentLocationMapItem:MKMapItem = MKMapItem.mapItemForCurrentLocation()
MKMapItem.openMapsWithItems([currentLocationMapItem, mapItem], launchOptions: launchOptions as [NSObject : AnyObject])
}
有任何想法吗?谢谢。