我是
Swift的新人,我遵循本教程:
http://www.raywenderlich.com/90971/introduction-mapkit-swift-tutorial关于MapKit.问题是我在这行代码上有错误
- let placemark = MKPlacemark(coordinate: self.coordinate,addressDictionary: addressDict)
- 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
- }
请帮忙.
解决方法
您需要将您的字幕转换为AnyObject,如下所示:
- let addressDict = [String(kABPersonAddressStreetKey): self.subtitle as! AnyObject]
您的完整代码将是:
- 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
- }