Skip to content

Commit 05bf5aa

Browse files
Leverage Bedrock's IndexedCollection
1 parent c3b1e9b commit 05bf5aa

File tree

3 files changed

+4
-126
lines changed

3 files changed

+4
-126
lines changed

Alidade.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Alidade/Models/Document/IndexedPinCollection.swift

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Created by Marquis Kurt on 18-06-2025.
66
//
77

8+
import Bedrock
89
import Foundation
910
import MCMap
1011

@@ -26,74 +27,4 @@ import MCMap
2627
/// }
2728
/// }
2829
/// ```
29-
struct IndexedPinCollection {
30-
fileprivate typealias InternalContainer = [CartographyMapPin]
31-
/// A structure representing an element in the collection.
32-
struct Element: Identifiable, Equatable, Hashable {
33-
/// A unique identifier for the element.
34-
var id: Int { index }
35-
36-
/// The index where the pin can be found in the source list.
37-
var index: Int
38-
39-
/// The contents of the pin.
40-
var content: CartographyMapPin
41-
}
42-
43-
private var elements: [CartographyMapPin]
44-
45-
/// Create a collection from an existing array of pins.
46-
init(_ elements: [CartographyMapPin]) {
47-
self.elements = elements
48-
}
49-
}
50-
51-
extension IndexedPinCollection: Codable {
52-
func encode(to encoder: any Encoder) throws {
53-
var container = encoder.singleValueContainer()
54-
try container.encode(elements)
55-
}
56-
57-
init(from decoder: any Decoder) throws {
58-
let container = try decoder.singleValueContainer()
59-
self.elements = try container.decode(InternalContainer.self)
60-
}
61-
}
62-
63-
extension IndexedPinCollection: Equatable {}
64-
65-
extension IndexedPinCollection: Hashable {
66-
func hash(into hasher: inout Hasher) {
67-
hasher.combine(elements)
68-
}
69-
}
70-
71-
extension IndexedPinCollection: ExpressibleByArrayLiteral {
72-
typealias ArrayLiteralElement = CartographyMapPin
73-
74-
init(arrayLiteral elements: CartographyMapPin...) {
75-
self.init(elements)
76-
}
77-
}
78-
79-
extension IndexedPinCollection: Collection {
80-
typealias Index = [CartographyMapPin].Index
81-
82-
var startIndex: Array<CartographyMapPin>.Index {
83-
elements.startIndex
84-
}
85-
86-
var endIndex: Array<CartographyMapPin>.Index {
87-
elements.endIndex
88-
}
89-
90-
subscript(position: Array<CartographyMapPin>.Index) -> Element {
91-
return Element(index: Int(position), content: elements[position])
92-
}
93-
94-
func index(after index: Array<CartographyMapPin>.Index) -> Array<CartographyMapPin>.Index {
95-
elements.index(after: index)
96-
}
97-
}
98-
99-
extension IndexedPinCollection: RandomAccessCollection {}
30+
typealias IndexedPinCollection = IndexedCollection<CartographyMapPin>

AlidadeTests/IndexedPinCollectionTests.swift

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)