Skip to content

Commit

Permalink
Remove leftovers from BasicMapExample (#2290)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksproger committed Sep 9, 2024
1 parent ba18626 commit c1ec37b
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 24 deletions.
14 changes: 0 additions & 14 deletions Apps/Examples/Examples/All Examples/BasicMapExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,6 @@ final class BasicMapExample: UIViewController, ExampleProtocol {

view.addSubview(mapView)

let targets = [
FeaturesetQueryTarget(
featureset: .layer("my-layer"),
filter: Exp(.eq) {
Exp(.get) { "type" }
"hotel"
}
),
FeaturesetQueryTarget(featureset: .featureset("poi", importId: "basemap"))
]
mapView.mapboxMap.queryRenderedFeatures(with: CGPoint(x: 0, y: 0),
targets: targets) { _ in
// handle features in result
}
}

override func viewDidAppear(_ animated: Bool) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/MapboxMaps/Style/Style+Localization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ extension StyleManager {
options: .caseInsensitive)

if case .expression(let textField) = symbolLayer.textField {
var stringExpression = String(decoding: try JSONEncoder().encode(textField), as: UTF8.self)
var stringExpression = String(data: try JSONEncoder().encode(textField), encoding: .utf8)!
stringExpression.updateOnceExpression(replacement: replacement, regex: expressionCoalesce)
stringExpression.updateExpression(replacement: replacement, regex: expressionAbbr)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ final class AnnotationManagerImplTests: XCTestCase {
func checkExpression(key: String, props: [String: Any]) throws {
let value = try XCTUnwrap(props[key] as? [Any])
let valueData = try XCTUnwrap(JSONSerialization.data(withJSONObject: value))
let valueString = try XCTUnwrap(String(decoding: valueData, as: UTF8.self))
let valueString = try XCTUnwrap(String(data: valueData, encoding: .utf8))

let fallbackValue = me.layerProperties[key] ?? StyleManager.layerPropertyDefaultValue(for: .symbol, property: key).value
let fallbackValueData = JSONSerialization.isValidJSONObject(fallbackValue)
? try XCTUnwrap(JSONSerialization.data(withJSONObject: fallbackValue))
: Data(String(describing: fallbackValue).utf8)
let fallbackValueString = try XCTUnwrap(String(decoding: fallbackValueData, as: UTF8.self))
let fallbackValueString = try XCTUnwrap(String(data: fallbackValueData, encoding: .utf8))

let expectedString = "[\"coalesce\",[\"get\",\"\(key)\",[\"get\",\"layerProperties\"]],\(fallbackValueString)]"
XCTAssertEqual(valueString, expectedString)
Expand Down
2 changes: 1 addition & 1 deletion Tests/MapboxMapsTests/Helpers/Encodable+JsonString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import Foundation

extension Encodable {
func jsonString() throws -> String {
try String(decoding: JSONEncoder().encode(self), as: UTF8.self)
String(data: try JSONEncoder().encode(self), encoding: .utf8)!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ final class FormatOptionsTests: XCTestCase {

let encoded = try DictionaryEncoder().encode(formatOptions)
XCTAssertEqual(
String(decoding: try JSONSerialization.data(withJSONObject: encoded["font-scale"] as Any), as: UTF8.self),
String(data: try JSONSerialization.data(withJSONObject: encoded["font-scale"] as Any), encoding: .utf8),
#"["case",[">=",["to-number",["get","point_count"]],4],1,2]"#
)
XCTAssertEqual(
String(decoding: try JSONSerialization.data(withJSONObject: encoded["text-font"] as Any), as: UTF8.self),
String(data: try JSONSerialization.data(withJSONObject: encoded["text-font"] as Any), encoding: .utf8),
#"["case",[">=",["to-number",["get","point_count"]],4],["Open Sans Semibold"],["Arial Unicode MS Bold"]]"#
)
XCTAssertEqual(
String(decoding: try JSONSerialization.data(withJSONObject: encoded["text-color"] as Any), as: UTF8.self),
String(data: try JSONSerialization.data(withJSONObject: encoded["text-color"] as Any), encoding: .utf8),
##"["case",[">=",["to-number",["get","point_count"]],4],"#ffffff","#000000"]"##
)
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/MapboxMapsTests/Style/StyleIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ internal class StyleIntegrationTests: MapViewIntegrationTestCase {
XCTAssertNoThrow {
let convertedExpression = try self.mapView.mapboxMap.convertExpressionForLocalization(symbolLayer: symbolLayer, localeValue: "zh")
let data = try JSONSerialization.data(withJSONObject: XCTUnwrap(convertedExpression), options: [.prettyPrinted])
let convertedString = String(decoding: data, as: UTF8.self).replacingOccurrences(of: " ", with: "").replacingOccurrences(of: "\n", with: "")
let convertedString = String(data: data, encoding: .utf8)!.replacingOccurrences(of: " ", with: "").replacingOccurrences(of: "\n", with: "")

let result = "[\"format\",[\"coalesce\",[\"get\",\"name_zh\"],[\"get\",\"name\"]]]"
XCTAssertEqual(result, convertedString)
Expand Down Expand Up @@ -261,7 +261,7 @@ internal class StyleIntegrationTests: MapViewIntegrationTestCase {
],
]

let styleJSON: String = String(decoding: try! JSONSerialization.data(withJSONObject: styleJSONObject, options: [.prettyPrinted]), as: UTF8.self)
let styleJSON: String = String(data: try! JSONSerialization.data(withJSONObject: styleJSONObject, options: [.prettyPrinted]), encoding: .utf8)!
XCTAssertFalse(styleJSON.isEmpty, "ValueConverter should create valid JSON string.")

let styleJSONFinishedLoading = expectation(description: "Style JSON has finished loading")
Expand Down
2 changes: 1 addition & 1 deletion Tests/MapboxMapsTests/Style/StyleTransitionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class StyleTransitionTests: XCTestCase {
let encoder = JSONEncoder()
encoder.outputFormatting = .sortedKeys
let encodedTransition = try! encoder.encode(transition)
let dataString = String(decoding: encodedTransition, as: UTF8.self)
let dataString = String(data: encodedTransition, encoding: .utf8)

XCTAssertEqual(dataString, jsonString)
}
Expand Down

0 comments on commit c1ec37b

Please sign in to comment.