From 5dbdaee593724b6145fc3b93e2cabc268d23bb8d Mon Sep 17 00:00:00 2001 From: Mai Mai Date: Tue, 12 Nov 2024 12:00:31 +0200 Subject: [PATCH] Expose init for ResultChildMetadata with field values (#340) * Expose init for ResultChildMetadata with field values Co-authored-by: Nastassia Makaranka --- CHANGELOG.md | 2 ++ .../Search Results/ResultChildMetadata.swift | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba6a2523..7dce6870 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ Guide: https://keepachangelog.com/en/1.0.0/ +- [ResultChildMetadata] Add ResultChildMetadata.init(category:coordinate:mapboxId:name) + ## 2.6.0-rc.1 - [Core] Update dependencies diff --git a/Sources/MapboxSearch/PublicAPI/Search Results/ResultChildMetadata.swift b/Sources/MapboxSearch/PublicAPI/Search Results/ResultChildMetadata.swift index 9439c80e..9077a8db 100644 --- a/Sources/MapboxSearch/PublicAPI/Search Results/ResultChildMetadata.swift +++ b/Sources/MapboxSearch/PublicAPI/Search Results/ResultChildMetadata.swift @@ -23,4 +23,27 @@ public struct ResultChildMetadata: Codable, Hashable { } self.name = resultChildMetadata.name } + + /// Initializes a new instance of `ResultChildMetadata` with optional category, coordinates, and name, + /// and a required `mapboxId`. + /// + /// - Parameters: + /// - mapboxId: A required `String` that uniquely identifies the Mapbox object. This is a required + /// parameter and must be provided during initialization. + /// - name: An optional `String` representing the name of the result. + /// - category: An optional `String` representing the category of the result. + /// - coordinate: An optional `CLLocationCoordinate2D` representing the geographical location + /// associated with the result. If provided, it is transformed to a `CLLocationCoordinate2DCodable` + /// instance for storage. + public init( + mapboxId: String, + name: String? = nil, + category: String? = nil, + coordinate: CLLocationCoordinate2D? = nil + ) { + self.category = category + self.coordinatesCodable = coordinate.map(CLLocationCoordinate2DCodable.init) + self.mapboxId = mapboxId + self.name = name + } }