gpt4 book ai didi

ios - Swift 语法问题 : Nested class type cannot be used when declaring variables of that type

转载 作者:行者123 更新时间:2023-11-28 06:39:23 25 4
gpt4 key购买 nike

<分区>

我没有将我的 pin 类称为“EventMapViewPin”,而是想像这样嵌套该类。

class EventMapView: MKMapView {

class Pin: MapPin {

var event: Event!

convenience init(event: Event, coordinate: CLLocationCoordinate2D, title: String, subtitle: String) {
self.init(coordinate: coordinate, title: title, subtitle: subtitle)
}

}

}

class MapPin: NSObject, MKAnnotation {

var coordinate: CLLocationCoordinate2D
var title: String?
var subtitle: String?

init(coordinate: CLLocationCoordinate2D, title: String, subtitle: String) {
self.coordinate = coordinate
self.title = title
self.subtitle = subtitle
}

}

但是我不能在这个上下文中使用这个类。

var collector = [EventMapView.Pin]()

错误:无效使用'()'调用非函数类型的函数

作为此 question 的后续,我很惊讶地发现这种语法是非法的。当类以这种有意识的命名空间方式嵌套时,我将如何声明 [EventMapView.Pin] 类型的变量?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com