Skip to content

Commit

Permalink
Merge branch 'main' into 187-xcode-cloud-support-for-version-200+
Browse files Browse the repository at this point in the history
  • Loading branch information
aokj4ck authored Apr 19, 2024
2 parents 7dc5502 + b30ea74 commit 621abf3
Show file tree
Hide file tree
Showing 41 changed files with 247 additions and 39 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ Guide: https://keepachangelog.com/en/1.0.0/

<!-- Add changes for active work here -->

- [SearchResult] Add support for `mapboxId` field when availalbe.
- [FavoriteRecord] Add support for `mapboxId` field when availalbe.
- [HistoryRecord] Add support for `mapboxId` field when availalbe.
- [Discover] Add more complete support for `mapboxId` field in Result subtype when availalbe.
- [Address Autofill] Add more complete support for `mapboxId` field in Result and Suggestion subtypes when availalbe.
- [Place Autocomplete] Add more complete support for `mapboxId` field in Result and Suggestion subtypes when availalbe.
- [Demo] Add `mapboxId` table view cell to PlaceAutocomplete detail view controller when available.

- [Offline] Remove `CoreOfflineIndexChangeEventType` extension previously used for development.
- [Core] Remove usages of `@_implementationOnly import` due to compilation issue.

- [Offline] Add optional `language` parameter to SearchOfflineManager.createTilesetDescriptor and SearchOfflineManager.createPlacesTilesetDescriptor functions.
- [Tests] Add Spanish language offline search test.

- [Offline] Added OfflineIndexObserver which accepts two blocks for indexChanged or error events. This can be assigned to the offline search engine to receive state updates.

- [Offline] Change default tileset name to `mbx-main`
Expand All @@ -16,6 +30,7 @@ Guide: https://keepachangelog.com/en/1.0.0/
- [Tests] Demonstrate providing a `Geometry(point: NSValue(mkCoordinate: CLLocationCoordinate2D))` with `TileRegionLoadOptions.build` function.
- [Core] Increment minimum MapboxCommon version from 24.0.0 to 24.2.0.

**MapboxCoreSearch**: v2.0.0-alpha.16
**MapboxCommon**: v24.2.0

## 2.0.0-rc.3
Expand Down
4 changes: 2 additions & 2 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
binary "https://api.mapbox.com/downloads/v2/carthage/search-core-sdk/MapboxCoreSearch.xcframework.json" == 2.0.0-alpha.14
binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon.json" == 24.2.0
binary "https://api.mapbox.com/downloads/v2/carthage/search-core-sdk/MapboxCoreSearch.xcframework.json" == 2.0.0-alpha.16
binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon.json" == 24.2.0
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon.json" "24.2.0"
binary "https://api.mapbox.com/downloads/v2/carthage/search-core-sdk/MapboxCoreSearch.xcframework.json" "2.0.0-alpha.14"
binary "https://api.mapbox.com/downloads/v2/carthage/search-core-sdk/MapboxCoreSearch.xcframework.json" "2.0.0-alpha.16"
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import PackageDescription
import Foundation

let (coreSearchVersion, coreSearchVersionHash) = ("2.0.0-alpha.14", "c3e61341f2beb1b8043f3c71caccdd9bea12a23f221cb90eb452e2abe299c3e0")
let (coreSearchVersion, coreSearchVersionHash) = ("2.0.0-alpha.16", "315d5f6ed1446f5ca5d62cc6e4124ae01fa271ad9d675268e886c38149db8532")

let commonMinVersion = Version("24.2.0")
let commonMaxVersion = Version("25.0.0")
Expand Down
6 changes: 6 additions & 0 deletions Sources/Demo/PlaceAutocompleteDetailsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ extension PlaceAutocomplete.Result {
)
}

if let mapboxId {
components.append(
(name: "Mapbox ID", value: mapboxId)
)
}

return components
}
}
10 changes: 4 additions & 6 deletions Sources/MapboxSearch/InternalAPI/CoreAliases.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
@_implementationOnly import MapboxCommon_Private
import MapboxCommon_Private
import MapboxCoreSearch
import MapboxCoreSearch_Private

/// https://forums.swift.org/t/update-on-implementation-only-imports/26996
@_implementationOnly import MapboxCoreSearch
@_implementationOnly import MapboxCoreSearch_Private

// Note: This file included in MapboxSearch and MapboxSearchTests targets
// Note: This file is included in MapboxSearch and MapboxSearchTests targets

typealias CoreSearchEngine = MapboxCoreSearch.SearchEngine
typealias CoreSearchResponse = MapboxCoreSearch_Private.SearchResponse
Expand Down
57 changes: 53 additions & 4 deletions Sources/MapboxSearch/InternalAPI/CoreSearchEngineStatics.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,60 @@
import Foundation

enum CoreSearchEngineStatics {
static func createTilesetDescriptor(dataset: String, version: String) -> MapboxCommon.TilesetDescriptor {
CoreSearchEngine.createTilesetDescriptor(forDataset: dataset, version: version)
enum Constants {
static let delimiter = "_"
}

static func createPlacesTilesetDescriptor(dataset: String, version: String) -> MapboxCommon.TilesetDescriptor {
CoreSearchEngine.createPlacesTilesetDescriptor(forDataset: dataset, version: version)
static func createTilesetDescriptor(dataset: String, version: String, language: String? = nil) -> MapboxCommon
.TilesetDescriptor {
let identifier: String
if let language {
if ISOLanguages.contains(language: language) {
identifier = dataset + Constants.delimiter + language
} else {
_Logger.searchSDK
.warning(
"Provided language code '\(language)' for tileset is non-ISO. Dataset '\(dataset)' without language will be used."
)
identifier = dataset
}
} else {
identifier = dataset
}
return CoreSearchEngine.createTilesetDescriptor(forDataset: identifier, version: version)
}

static func createPlacesTilesetDescriptor(dataset: String, version: String, language: String? = nil) -> MapboxCommon
.TilesetDescriptor {
let identifier: String
if let language {
if ISOLanguages.contains(language: language) {
identifier = dataset + Constants.delimiter + language
} else {
_Logger.searchSDK
.warning(
"Provided language code '\(language)' for places tileset is non-ISO. Dataset '\(dataset)' without language will be used."
)
identifier = dataset
}
} else {
identifier = dataset
}
return CoreSearchEngine.createPlacesTilesetDescriptor(forDataset: identifier, version: version)
}
}

enum ISOLanguages {
static func contains(language: String) -> Bool {
var validLanguage: Bool
if #available(iOS 16, *) {
validLanguage = Locale.LanguageCode.isoLanguageCodes
.map(\.identifier)
.contains(language)
} else {
validLanguage = Locale.isoLanguageCodes
.contains(language)
}
return validLanguage
}
}
6 changes: 6 additions & 0 deletions Sources/MapboxSearch/PublicAPI/FavoriteRecord.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ public struct FavoriteRecord: IndexableRecord, SearchResult, Codable, Equatable
/// Displayable name of the record.
public var name: String

/// A unique identifier for the geographic feature
public var mapboxId: String?

/**
The feature name, as matched by the search algorithm.

Expand Down Expand Up @@ -79,6 +82,7 @@ public struct FavoriteRecord: IndexableRecord, SearchResult, Codable, Equatable
/// - resultType: Favorite result type
public init(
id: String? = nil,
mapboxId: String? = nil,
name: String,
matchingName: String?,
coordinate: CLLocationCoordinate2D,
Expand All @@ -93,6 +97,7 @@ public struct FavoriteRecord: IndexableRecord, SearchResult, Codable, Equatable
metadata: SearchResultMetadata? = nil
) {
self.id = id ?? UUID().uuidString
self.mapboxId = mapboxId
self.name = name
self.matchingName = matchingName
self.coordinateCodable = .init(coordinate)
Expand All @@ -118,6 +123,7 @@ public struct FavoriteRecord: IndexableRecord, SearchResult, Codable, Equatable
) {
self.init(
id: id,
mapboxId: searchResult.mapboxId,
name: name,
matchingName: searchResult.matchingName,
coordinate: searchResult.coordinate,
Expand Down
5 changes: 5 additions & 0 deletions Sources/MapboxSearch/PublicAPI/HistoryRecord.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public struct HistoryRecord: IndexableRecord, SearchResult, Codable, Hashable {
/// Unique identifier
public private(set) var id: String

public private(set) var mapboxId: String?

/// Record's name
public private(set) var name: String

Expand Down Expand Up @@ -97,6 +99,7 @@ public struct HistoryRecord: IndexableRecord, SearchResult, Codable, Hashable {
/// - routablePoints: Coordinates of building entries
public init(
id: String = UUID().uuidString,
mapboxId: String?,
name: String,
matchingName: String?,
serverIndex: Int?,
Expand All @@ -112,6 +115,7 @@ public struct HistoryRecord: IndexableRecord, SearchResult, Codable, Hashable {
routablePoints: [RoutablePoint]? = nil
) {
self.id = id
self.mapboxId = mapboxId
self.name = name
self.matchingName = matchingName
self.serverIndex = serverIndex
Expand All @@ -138,6 +142,7 @@ public struct HistoryRecord: IndexableRecord, SearchResult, Codable, Hashable {
timestamp: Date = Date()
) {
self.id = searchResult.id
self.mapboxId = searchResult.mapboxId
self.name = searchResult.name
self.matchingName = searchResult.matchingName
self.serverIndex = searchResult.serverIndex
Expand Down
37 changes: 32 additions & 5 deletions Sources/MapboxSearch/PublicAPI/Offline/SearchOfflineManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,53 @@ public class SearchOfflineManager {
engine.setTileStore(searchTileStore.commonTileStore, completion: completion)
}

/// Creates TilesetDescriptor for offline search index data with provided dataset name and version.
// MARK: - Tileset with name, version, and language parameters

/// Creates TilesetDescriptor for offline search index data with provided dataset name, version, and language.
/// Providing nil or excluding the language parameter will use the dataset name as-is.
/// Providing a language will append it to the name.
/// - Parameters:
/// - dataset: dataset name
/// - version: dataset version
/// - language: Provide a ISO 639-1 Code language from NSLocale. Values will be appended to the place dataset
/// name.
/// - Returns: TilesetDescriptor for TileStore
public static func createTilesetDescriptor(dataset: String, version: String? = nil) -> MapboxCommon
public static func createTilesetDescriptor(
dataset: String,
version: String? = nil,
language: String? = nil
) -> MapboxCommon
.TilesetDescriptor {
CoreSearchEngineStatics.createTilesetDescriptor(dataset: dataset, version: version ?? "")
CoreSearchEngineStatics.createTilesetDescriptor(
dataset: dataset,
version: version ?? "",
language: language
)
}

/// Creates TilesetDescriptor for offline search boundaries with provided dataset name and version.
/// Providing nil or excluding the language parameter will use the places dataset name as-is.
/// Providing a language will append it to the name.
/// - Parameters:
/// - dataset: dataset name
/// - version: dataset version
/// - language: Provide a ISO 639-1 Code language from NSLocale. Values will be appended to the dataset name.
/// - Returns: TilesetDescriptor for TileStore
public static func createPlacesTilesetDescriptor(dataset: String, version: String? = nil) -> MapboxCommon
public static func createPlacesTilesetDescriptor(
dataset: String,
version: String? = nil,
language: String? = nil
) -> MapboxCommon
.TilesetDescriptor {
CoreSearchEngineStatics.createPlacesTilesetDescriptor(dataset: dataset, version: version ?? "")
CoreSearchEngineStatics.createPlacesTilesetDescriptor(
dataset: dataset,
version: version ?? "",
language: language
)
}

// MARK: - Default tileset

/// Creates TilesetDescriptor for offline search index data using default dataset name.
/// - Returns: TilesetDescriptor for TileStore
public static func createDefaultTilesetDescriptor() -> MapboxCommon.TilesetDescriptor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import CoreLocation
import Foundation

class ExternalRecordPlaceholder: SearchResultSuggestion, CoreResponseProvider {
var mapboxId: String?

var originalResponse: CoreSearchResultResponse

var dataLayerIdentifier: String

var id: String

var mapboxId: String?

var name: String

var address: Address?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import CoreLocation
import Foundation

class SearchCategorySuggestionImpl: SearchCategorySuggestion, CoreResponseProvider {
var mapboxId: String?

var originalResponse: CoreSearchResultResponse

var id: String

var mapboxId: String?

var name: String

var address: Address?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public protocol SearchResult {
/// Result name.
var name: String { get }

/// A unique identifier for the geographic feature
var mapboxId: String? { get }

/// Icon name according to [Mapbox Maki icon set](https://github.com/mapbox/maki/)
var iconName: String? { get }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import CoreLocation
import Foundation

class SearchResultSuggestionImpl: SearchResultSuggestion, CoreResponseProvider {
var mapboxId: String?

var originalResponse: CoreSearchResultResponse

let dataLayerIdentifier = SearchEngine.providerIdentifier

var id: String

var mapboxId: String?

var name: String

var address: Address?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public protocol SearchSuggestion {
/// - Attention: Mapbox backend may change the identifier of the object in the future.
var id: String { get }

/// A unique identifier for the geographic feature
var mapboxId: String? { get }

/// Suggestion name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import CoreLocation
import Foundation

class ServerSearchResult: SearchResult, SearchResultSuggestion, CoreResponseProvider {
var mapboxId: String?

var distance: CLLocationDistance?

var originalResponse: CoreSearchResultResponse
Expand Down Expand Up @@ -37,6 +35,8 @@ class ServerSearchResult: SearchResult, SearchResultSuggestion, CoreResponseProv

var id: String

var mapboxId: String?

var name: String

var matchingName: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ extension AddressAutofill {
}
let result = AddressAutofill.Result(
name: suggestion.name,
mapboxId: suggestion.mapboxId,
formattedAddress: suggestion.formattedAddress,
coordinate: coordinate,
addressComponents: suggestion.addressComponents
Expand Down Expand Up @@ -248,6 +249,7 @@ extension AddressAutofill {

return Suggestion(
name: name,
mapboxId: result.mapboxId,
formattedAddress: fullAddress,
coordinate: result.center?.value,
addressComponents: resultAddress,
Expand Down Expand Up @@ -287,6 +289,7 @@ extension AddressAutofill {

let autofillResult = AddressAutofill.Result(
name: result.name,
mapboxId: result.mapboxId,
formattedAddress: formattedAddress,
coordinate: result.coordinate,
addressComponents: addressComponents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ extension AddressAutofill {
/// Result name.
public let name: String

/// A unique identifier for the geographic feature
public let mapboxId: String?

/// Textual representation of the address.
public let formattedAddress: String

Expand All @@ -16,11 +19,13 @@ extension AddressAutofill {

init(
name: String,
mapboxId: String?,
formattedAddress: String,
coordinate: CLLocationCoordinate2D,
addressComponents: NonEmptyArray<AddressComponent>
) {
self.name = name
self.mapboxId = mapboxId
self.formattedAddress = formattedAddress
self.coordinate = coordinate
self.addressComponents = addressComponents
Expand Down
Loading

0 comments on commit 621abf3

Please sign in to comment.