Skip to content

Commit

Permalink
Add support for sendable data
Browse files Browse the repository at this point in the history
  • Loading branch information
vospennikov committed Dec 28, 2023
1 parent 53f830e commit 0c08c5e
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Sources/ClusterMap/Public/Core/ClusterManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import MapKit
public actor ClusterManager<Annotation: CoordinateIdentifiable>
where
Annotation: Identifiable,
Annotation: Hashable
Annotation: Hashable,
Annotation: Sendable
{
private var tree = QuadTree<Annotation>(rect: .world)
private let configuration: Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import MapKit

/// Calculate the position for a cluster of `CLLocationCoordinate2D` instances within a specified `MKMapRect`.
public protocol ClusterAlignmentStrategy {
public protocol ClusterAlignmentStrategy: Sendable {
/// Calculates the position for a cluster of `CLLocationCoordinate2D` instances.
/// - Parameters:
/// - annotations: The array of `CLLocationCoordinate2D` instances.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public extension ClusterManager {
/// )
/// let manager = ClusterManager(configuration: customConfig)
/// ```
struct Configuration {
struct Configuration: Sendable {
/// Maximum depth for clustering.
///
/// Beyond this zoom level, annotations will be displayed individually.
Expand Down Expand Up @@ -127,7 +127,7 @@ public extension ClusterManager {
/// }
/// }
/// )
public let cellSizeForZoomLevel: (Int) -> CGSize
public let cellSizeForZoomLevel: @Sendable (Int) -> CGSize

public init(
maxZoomLevel: Double = 20,
Expand All @@ -136,7 +136,7 @@ public extension ClusterManager {
shouldDistributeAnnotationsOnSameCoordinate: Bool = true,
distanceFromContestedLocation: Double = 3,
clusterPosition: ClusterAlignment = .nearCenter,
cellSizeForZoomLevel: @escaping (Int) -> CGSize = { zoom in
cellSizeForZoomLevel: @Sendable @escaping (Int) -> CGSize = { zoom in
switch zoom {
case 13...15: CGSize(width: 64, height: 64)
case 16...18: CGSize(width: 32, height: 32)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public extension ClusterManager {
/// break
/// }
/// ```
enum AnnotationType: Equatable, Hashable, Identifiable where Annotation: Equatable {
enum AnnotationType: Equatable, Hashable, Identifiable, Sendable where Annotation: Equatable {
public var id: Self { self }

/// Represents an individual annotation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public extension ClusterManager {
/// `ClusterAnnotation` is a struct that holds the information for a group of annotations that have been clustered
/// together. It contains the geographical coordinate for the cluster and an array of `Annotation` objects that
/// belong to this cluster.
struct ClusterAnnotation: Equatable, Hashable, Identifiable {
struct ClusterAnnotation: Equatable, Hashable, Identifiable, Sendable {
/// A unique identifier
public let id = UUID()

Expand Down
2 changes: 1 addition & 1 deletion Sources/ClusterMap/Public/Models/Output/Difference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

public extension ClusterManager {
/// Represents the differences between the current and new sets of annotations.
struct Difference {
struct Difference: Sendable {
/// An array of objects that should be inserted.
public var insertions: [AnnotationType] = []

Expand Down

0 comments on commit 0c08c5e

Please sign in to comment.