Skip to content

Commit affa693

Browse files
committed
fix(ios): enforce ItemFeatureEvents conformance at compile time
Removed fatalError/assertionFailure stubs from ItemView base class and dropped its ItemFeatureEvents conformance. Each *Impl subclass now conforms to ItemFeatureEvents directly, making a missing override a compiler error. MapViewImpl casts through the @objc boundary with preconditionFailure to catch any future subclass that omits the conformance.
1 parent ca23b30 commit affa693

6 files changed

Lines changed: 23 additions & 25 deletions

File tree

ios/ArrowViewImpl.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Foundation
33

44
import heresdk
55

6-
@objcMembers public class ArrowViewImpl: ItemView {
6+
@objcMembers public class ArrowViewImpl: ItemView, ItemFeatureEvents {
77

88
var mapArrow: MapArrow?
99

@@ -19,7 +19,7 @@ import heresdk
1919
didSet { updateFeature() }
2020
}
2121

22-
public override func updateFeature() {
22+
public func updateFeature() {
2323
guard geoPolyline.count > 1 else { return }
2424
let coords = toCoordinatesList(raw: geoPolyline)
2525
guard coords.count > 1 else { return }
@@ -39,7 +39,7 @@ import heresdk
3939
}
4040
}
4141

42-
public override func removeFeature() {
42+
public func removeFeature() {
4343
if let old = mapArrow {
4444
parentMap?.mapScene.removeMapArrow(old)
4545
}

ios/Helpers/ItemView.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,10 @@ public protocol ItemFeatureEvents {
88
}
99

1010
@objc(ItemView)
11-
public class ItemView: UIView, ItemFeatureEvents {
12-
11+
public class ItemView: UIView {
12+
1313
weak public var parentMap: MapView?
14-
15-
public func updateFeature() {
16-
fatalError("updateFeature() must be overridden in subclasses")
17-
}
18-
19-
public func removeFeature() {
20-
fatalError("removeFeature() must be overridden in subclasses")
21-
}
22-
14+
2315
public func assignToMap(map: MapView) {
2416
parentMap = map
2517
}

ios/MapViewImpl.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,19 @@ import heresdk
5858

5959
// Called by MapView.mm when a child ItemView is mounted
6060
@objc public func addItemView(_ itemView: ItemView) {
61+
guard let feature = itemView as? ItemFeatureEvents else {
62+
preconditionFailure("\(type(of: itemView)) must conform to ItemFeatureEvents")
63+
}
6164
itemView.assignToMap(map: mapView)
62-
itemView.updateFeature()
65+
feature.updateFeature()
6366
}
6467

6568
// Called by MapView.mm when a child ItemView is unmounted
6669
@objc public func removeItemView(_ itemView: ItemView) {
67-
itemView.removeFeature()
70+
guard let feature = itemView as? ItemFeatureEvents else {
71+
preconditionFailure("\(type(of: itemView)) must conform to ItemFeatureEvents")
72+
}
73+
feature.removeFeature()
6874
}
6975

7076
public func onTap(origin: Point2D) {

ios/MarkerViewImpl.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22

33
import heresdk
44

5-
@objcMembers public class MarkerViewImpl: ItemView {
5+
@objcMembers public class MarkerViewImpl: ItemView, ItemFeatureEvents {
66

77
var currentMapMarker: MapMarker?
88

@@ -22,7 +22,7 @@ import heresdk
2222
didSet { updateFeature() }
2323
}
2424

25-
public override func updateFeature() {
25+
public func updateFeature() {
2626
guard let urlString = image["uri"] as? String,
2727
let url = URL(string: urlString)
2828
else {
@@ -66,7 +66,7 @@ import heresdk
6666
}.resume()
6767
}
6868

69-
public override func removeFeature() {
69+
public func removeFeature() {
7070
if let oldMapMarker = currentMapMarker {
7171
parentMap?.mapScene.removeMapMarker(oldMapMarker)
7272
}

ios/PolygonViewImpl.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Foundation
33

44
import heresdk
55

6-
@objcMembers public class PolygonViewImpl: ItemView {
6+
@objcMembers public class PolygonViewImpl: ItemView, ItemFeatureEvents {
77

88
var currentMapPolygon: MapPolygon?
99

@@ -27,7 +27,7 @@ import heresdk
2727
didSet { updateFeature() }
2828
}
2929

30-
public override func updateFeature() {
30+
public func updateFeature() {
3131
var mapPolygon: MapPolygon?
3232

3333
if geoCoordinates.count > 2 {
@@ -60,7 +60,7 @@ import heresdk
6060
}
6161
}
6262

63-
public override func removeFeature() {
63+
public func removeFeature() {
6464
if let oldMapPolygon = currentMapPolygon {
6565
parentMap?.mapScene.removeMapPolygon(oldMapPolygon)
6666
}

ios/PolylineViewImpl.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Foundation
33

44
import heresdk
55

6-
@objcMembers public class PolylineViewImpl: ItemView {
6+
@objcMembers public class PolylineViewImpl: ItemView, ItemFeatureEvents {
77

88
var mapPolyline: MapPolyline?
99

@@ -48,7 +48,7 @@ import heresdk
4848
didSet { updateFeature() }
4949
}
5050

51-
public override func updateFeature() {
51+
public func updateFeature() {
5252
guard geoPolyline.count > 1 else { return }
5353

5454
let coords = toCoordinatesList(raw: geoPolyline)
@@ -87,7 +87,7 @@ import heresdk
8787
}
8888
}
8989

90-
public override func removeFeature() {
90+
public func removeFeature() {
9191
if let old = mapPolyline {
9292
parentMap?.mapScene.removeMapPolyline(old)
9393
}

0 commit comments

Comments
 (0)