Skip to content

Commit

Permalink
Fix build warnings (#274)
Browse files Browse the repository at this point in the history
### Description

- Fix deprecated function usage
- Fix data encoding warnings
- Remove documentation links to solve warning
- Suppress cyclomatic complexity warning (can be fixed in the future)
  • Loading branch information
aokj4ck authored Jul 18, 2024
1 parent 7999375 commit 538db98
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Sources/Demo/Examples/MapboxBoundingBoxController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MapboxBoundingBoxController: MapsViewController {

updateSearchResults(proximity: mapboxSFOfficeCoordinate)

mapDraggingSubscription = mapView.mapboxMap.onEvery(event: .cameraChanged) { [weak self] _ in
mapDraggingSubscription = mapView.mapboxMap.onCameraChanged.observe { [weak self] _ in
guard let self else { return }
draggingRefreshTimer?.invalidate()
draggingRefreshTimer = Timer.scheduledTimer(
Expand Down
10 changes: 6 additions & 4 deletions Sources/MapboxSearch/PublicAPI/SearchOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,10 @@ public struct SearchOptions {
}

func toCore() -> CoreSearchOptions {
let searchLanguages: [String]
if let localeLanguageCode = locale?.languageCode {
searchLanguages = [localeLanguageCode]
let searchLanguages: [String] = if let localeLanguageCode = locale?.languageCode {
[localeLanguageCode]
} else {
searchLanguages = languages
languages
}

let timeDeviation = routeOptions?.deviation.time.map { $0 / 60 }.map(NSNumber.init(value:))
Expand Down Expand Up @@ -269,6 +268,7 @@ public struct SearchOptions {
}
}

// swiftlint:disable cyclomatic_complexity
/// Build new instance, validating each field over endpoint specification.
/// - Parameter apiType: actual SearchEngine endpoint
/// - Returns: New instance with valid fields
Expand Down Expand Up @@ -379,6 +379,8 @@ public struct SearchOptions {
return validSearchOptions
}

// swiftlint:enable cyclomatic_complexity

/// Replace missing values with values from the other instance
///
/// Only `nil` values would be replaced. Each existing value will persist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ public class FeedbackManager {
root["multiStepSearch"] = !isReproducible

let searchResultsJSON = (try? JSONSerialization.data(withJSONObject: root, options: [])).flatMap { String(
data: $0,
encoding: .utf8
decoding: $0, as: UTF8.self
) }
return searchResultsJSON
}
Expand Down Expand Up @@ -252,9 +251,9 @@ extension FeedbackManager {
guard let self else { return }

do {
let attributes = try self.buildFeedbackAttributes(template, event: event)
let attributes = try buildFeedbackAttributes(template, event: event)

self.sendFeedback(attributes: attributes, autoFlush: autoFlush)
sendFeedback(attributes: attributes, autoFlush: autoFlush)
} catch {
_Logger.searchSDK.debug("Unable to process FeedbackEvent", category: .telemetry)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Foundation

extension Discover {
/// Wraps parameters for Discover/Category searches.
/// Use this to provide arguments that narrow your search.
public struct Options {
/// Maximum number of results to return.
/// The maximum allowed value for SBS APIs is 100 results.
Expand All @@ -17,7 +19,7 @@ extension Discover {
/// English (en) language parameter, but Frankreich (“France”) with a German (de) language parameter.
public let language: Language

/// See ``MapboxSearch/Country/ISO3166_1_alpha2`` for the list of ISO 3166 alpha 2 country codes.
/// See `Country.ISO3166_1_alpha2` for the list of ISO 3166 alpha 2 country codes.
/// The default value is nil.
public let country: Country?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ extension SearchSuggestTypeTests {
}

func testDecodableWithCorruptedData() throws {
let data = "{}".data(using: .utf8)!
let data = try XCTUnwrap(String("{}").data(using: .utf8))

let assertionError = catchBadInstruction {
let decoder = JSONDecoder()
Expand Down

0 comments on commit 538db98

Please sign in to comment.