ios - 将 ray wenderlich mapkit 教程升级到 xcode 7 错误 mkplacemark

标签 ios xcode swift swift2 mkplacemark

我刚刚将 ray wenderlich mapkit 教程升级到 MKPlacemark 的 xcode 7 错误。我仍然只是编码方面的新手,我不是 100% 确定从哪里开始解决这个错误。我搜索了但不知道有用。

感谢您的帮助。非常感谢。

http://www.raywenderlich.com/90971/introduction-mapkit-swift-tutorial

这是我遇到错误的代码:

// annotation callout opens this mapItem in Maps app
func mapItem() -> MKMapItem {
    let addressDict = [String(kABPersonAddressStreetKey): self.subtitle]
    let placemark = MKPlacemark(coordinate: self.coordinate, addressDictionary: addressDict)

    let mapItem = MKMapItem(placemark: placemark)
    mapItem.name = self.title

    return mapItem

错误是:

无法使用列表类型“coordinate:CLLocationCoordinate2D, addressDictionary:[String : String?])”的参数调用类型“mkplacemark”的初始值设定项

再次感谢,

特拉维斯。

最佳答案

您需要将字幕转换为 AnyObject,如下所示:

let addressDict = [String(kABPersonAddressStreetKey): self.subtitle as!任何对象]

“func mapItem() -> MKMapItem { }”的完整代码将是:

func mapItem() -> MKMapItem {
    let addressDict = [String(kABPersonAddressStreetKey): self.subtitle as! AnyObject]
    let placemark = MKPlacemark(coordinate: self.coordinate, addressDictionary: addressDict)

    let mapItem = MKMapItem(placemark: placemark)
    mapItem.name = self.title

    return mapItem
  }

关于ios - 将 ray wenderlich mapkit 教程升级到 xcode 7 错误 mkplacemark,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32662148/

相关文章:

ios - 无法以编程方式检查下拉按钮中的按钮标题

ios - 不给superview加约束,可以吗?

ios - 对象是 NSMutableDictionary 的子类,但在 mutate 方法 (NSJSONSerialization) 上崩溃

ios - 具有方言的字符串中的 NSRange

ios - 升级到xcode 4.6和iOS 6.1后的警告用作先前参数的名称,而不用作选择器的一部分

ios - 如何使用 GPUImage 启用 64 位支持

ios - 尝试运行测试时获取 "unable to attach test reporter"

objective-c - 自动推送到其他 View Controller

ios - 为什么在 Swift 中初始化类时不需要所有对象?

ios - 编码复杂对象 swift 3.0