在Swift 2.0中,openMapsWithItems无法调用参数列表问题

在Swift 2.0中,openMapsWithItems无法调用参数列表问题,swift,apple-maps,swift2,Swift,Apple Maps,Swift2,我在将Swift 1.2代码转换为2.0时遇到了一些问题-这就是其中之一 我有一个功能,可以打开iOS地图应用程序,为某个位置提供方向。在改造之前,它一直运转良好。现在,我收到以下错误消息: Cannot invoke 'openMapsWithItems' with an argument list of type '([MKMapItem], launchOptions: [NSObject : AnyObject])' 这是我的代码(错误出现在最后一行): 有什么想法吗?谢谢。如中所示,

我在将Swift 1.2代码转换为2.0时遇到了一些问题-这就是其中之一

我有一个功能,可以打开iOS地图应用程序,为某个位置提供方向。在改造之前,它一直运转良好。现在,我收到以下错误消息:

Cannot invoke 'openMapsWithItems' with an argument list of type '([MKMapItem], launchOptions: [NSObject : AnyObject])'
这是我的代码(错误出现在最后一行):

有什么想法吗?谢谢。

如中所示,
openmpswithitems:launchOptions:
现在已从使用
[NSObject:AnyObject]更改
来获取
[String:AnyObject]?
,因此您必须声明(或强制转换)它

在代码行中更改代码

let launchOptions:NSDictionary = NSDictionary(object: MKLaunchOptionsDirectionsModeDriving, forKey: MKLaunchOptionsDirectionsModeKey)

最后一行呢

MKMapItem.openMapsWithItems([currentLocationMapItem, mapItem], launchOptions: launchOptions as [NSObject : AnyObject])

这应该行得通


旁注:您应该更改代码样式以允许Swift推断大多数类型。请停止用
var placemark:MKPlacemark=MKPlacemark(…)
伤害每个人的眼睛。另外,为了避免使用
NSDictionary
,请使用Swift的
Dictionary

声明
launchOptions
一样让launchOptions:[NSObject:AnyObject]=[mklaunchoptions-directions-modekey:mklaunchoptions-directions-modedriving]
并将
作为[NSObject:AnyObject]
删除,谢谢Kametrix,但我仍然收到以下错误:“无法使用类型为([MKMapItem],launchOptions:[NSObject:AnyObject])的参数列表调用openMapsWithItems。”。我已经清理了构建,以防出现问题,但它仍然不起作用。这太完美了。谢谢您的帮助。@vrwim Reduntant键入应该是一个编译器警告。我们应该把雷达归档。
let launchOptions = [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]
MKMapItem.openMapsWithItems([currentLocationMapItem, mapItem], launchOptions: launchOptions as [NSObject : AnyObject])
MKMapItem.openMapsWithItems([currentLocationMapItem, mapItem], launchOptions: launchOptions)