我跟随Ray Wenderlich MapKit教程,在
swift:
http://www.raywenderlich.com/90971/introduction-mapkit-swift-tutorial,当我创建了艺术品类,我得到了标题写的错误.我不知道我要做什么
这是代码:
这是代码:
class Artwork: NSObject,MKAnnotation { let title: String let locationName: String let discipline: String let coordinate: CLLocationCoordinate2D init(title: String,locationName: String,discipline: String,coordinate: CLLocationCoordinate2D) { self.title = title self.locationName = locationName self.discipline = discipline self.coordinate = coordinate super.init() } }
请帮忙!
解决方法
安装者在文档中:我们在
MKAnnotation protocol reference页面上看到属性标题必须是可选的.
相应更改:
class Artwork: NSObject,MKAnnotation { var title: String? let locationName: String let discipline: String let coordinate: CLLocationCoordinate2D init(title: String,coordinate: CLLocationCoordinate2D) { self.title = title self.locationName = locationName self.discipline = discipline self.coordinate = coordinate super.init() } }
ProTip:在Xcode中,CMD单击您的对象或定义(在您的情况下为MKAnnotation),以查看协议的声明方式及其要求.