【发布时间】:2020-08-19 15:25:09
【问题描述】:
我正在创建一个自定义 MKAnnotationView 类并试图找出它的初始化程序。到目前为止,我有这个:
class JumpSpotAnnotationView: MKAnnotationView {
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override init(annotation: MKAnnotation?, reuseIdentifier: String?) {
super.init(annotation: annotation, reuseIdentifier: reuseIdentifier)
self.annotation = annotation
self.reuseIdentifier = reuseIdentifier
}
}
在最后一行“self.reuseIdentifier = reuseIdentifier”我收到错误“无法分配给属性:'reuseIdentifier' 是一个只能获取的属性”。我不完全明白这意味着什么或如何解决它。如何正确创建重用标识符的初始化程序?另外,作为旁注,如果您感觉很慷慨,有人可以解释整个“必需的初始化”吗?我还是新手,想了解它,但文档实际上是空的。谢谢!
【问题讨论】:
标签: swift xcode class initialization mkannotationview