Format Swift files with SwiftFormat (#2385)

This commit is contained in:
Bart Louwers
2024-05-12 03:59:27 +02:00
committed by GitHub
parent 9bdc950a3b
commit 32f1bbc902
15 changed files with 540 additions and 550 deletions

View File

@@ -19,6 +19,11 @@ repos:
hooks: hooks:
- id: actionlint - id: actionlint
additional_dependencies: [shellcheck-py] additional_dependencies: [shellcheck-py]
- repo: https://github.com/nicklockwood/SwiftFormat
rev: "0.53.8"
hooks:
- id: swiftformat
args: [--swiftversion, "5.8"]
ci: ci:
# sometimes fails https://github.com/keith/pre-commit-buildifier/issues/13 # sometimes fails https://github.com/keith/pre-commit-buildifier/issues/13
skip: [buildifier] skip: [buildifier]

View File

@@ -1,8 +1,9 @@
#!/usr/bin/swift #!/usr/bin/swift
import Foundation
/// Generates Entitlement files .xcent for codesigning, containing the correct team id /// Generates Entitlement files .xcent for codesigning, containing the correct team id
import Swift import Swift
import Foundation
let fileManager = FileManager.default let fileManager = FileManager.default
@@ -16,12 +17,11 @@ guard let rawTeamIdEnv = getenv("IOS_DEVELOPMENT_TEAM") else {
let teamId2 = String(utf8String: rawTeamIdEnv) let teamId2 = String(utf8String: rawTeamIdEnv)
for file in contentsOfCurrentWorkingDirectory { for file in contentsOfCurrentWorkingDirectory {
if (file.pathExtension == "template") { if file.pathExtension == "template" {
var content = "" var content = ""
do { do {
content = try String(contentsOf: file, encoding: .utf8) content = try String(contentsOf: file, encoding: .utf8)
} } catch {
catch {
print("Error reading xcent file: \(error).") print("Error reading xcent file: \(error).")
} }
@@ -32,9 +32,8 @@ for file in contentsOfCurrentWorkingDirectory {
do { do {
try content.write(to: targetFile, atomically: false, encoding: .utf8) try content.write(to: targetFile, atomically: false, encoding: .utf8)
print("Entitlement " + targetFile.absoluteString + " generated.") print("Entitlement " + targetFile.absoluteString + " generated.")
} } catch {
catch {
print("Error writing xcent file: \(error).") print("Error writing xcent file: \(error).")
} }
} }
} }

View File

@@ -1,5 +1,5 @@
import XCTest
import MapLibre import MapLibre
import XCTest
/** /**
Test cases that ensure the inline examples in the project documentation Test cases that ensure the inline examples in the project documentation
@@ -29,7 +29,7 @@ class MLNDocumentationExampleTests: XCTestCase, MLNMapViewDelegate {
static let shared = MLNOfflineStorageMock() static let shared = MLNOfflineStorageMock()
func addPack(for: MLNOfflineRegion, withContext: Data, completionHandler: MLNOfflinePackAdditionCompletionHandler? = nil) { func addPack(for: MLNOfflineRegion, withContext: Data, completionHandler: MLNOfflinePackAdditionCompletionHandler? = nil) {
XCTAssert(MLNOfflineStorage.shared.responds(to: #selector(MLNOfflineStorage.shared.addPack(for:withContext:completionHandler:)))) XCTAssert(MLNOfflineStorage.shared.responds(to: #selector(MLNOfflineStorage.shared.addPack(for:withContext:completionHandler:))))
if let completionHandler = completionHandler { if let completionHandler {
completionHandler(nil, NSError(domain: "MLNDocumentationExampleError", code: 0, userInfo: [NSLocalizedDescriptionKey: "\(#function) is mocked and not functional."])) completionHandler(nil, NSError(domain: "MLNDocumentationExampleError", code: 0, userInfo: [NSLocalizedDescriptionKey: "\(#function) is mocked and not functional."]))
} }
} }
@@ -48,33 +48,33 @@ class MLNDocumentationExampleTests: XCTestCase, MLNMapViewDelegate {
styleLoadingExpectation = nil styleLoadingExpectation = nil
super.tearDown() super.tearDown()
} }
func mapView(_ mapView: MLNMapView, didFinishLoading style: MLNStyle) { func mapView(_: MLNMapView, didFinishLoading _: MLNStyle) {
styleLoadingExpectation.fulfill() styleLoadingExpectation.fulfill()
} }
func testMLNLight() { func testMLNLight() {
//#-example-code // #-example-code
let light = MLNLight() let light = MLNLight()
let position = MLNSphericalPosition(radial: 5, azimuthal: 180, polar: 80) let position = MLNSphericalPosition(radial: 5, azimuthal: 180, polar: 80)
light.position = NSExpression(forConstantValue: NSValue(mlnSphericalPosition: position)) light.position = NSExpression(forConstantValue: NSValue(mlnSphericalPosition: position))
light.anchor = NSExpression(forConstantValue: "map") light.anchor = NSExpression(forConstantValue: "map")
mapView.style?.light = light mapView.style?.light = light
//#-end-example-code // #-end-example-code
XCTAssertNotNil(mapView.style?.light) XCTAssertNotNil(mapView.style?.light)
} }
func testMLNTilePyramidOfflineRegion() { func testMLNTilePyramidOfflineRegion() {
class MLNStyle { class MLNStyle {
static var lightStyleURL: URL { static var lightStyleURL: URL {
return MLNDocumentationExampleTests.styleURL MLNDocumentationExampleTests.styleURL
} }
} }
typealias MLNOfflineStorage = MLNOfflineStorageMock typealias MLNOfflineStorage = MLNOfflineStorageMock
//#-example-code // #-example-code
let northeast = CLLocationCoordinate2D(latitude: 40.989329, longitude: -102.062592) let northeast = CLLocationCoordinate2D(latitude: 40.989329, longitude: -102.062592)
let southwest = CLLocationCoordinate2D(latitude: 36.986207, longitude: -109.049896) let southwest = CLLocationCoordinate2D(latitude: 36.986207, longitude: -109.049896)
let bbox = MLNCoordinateBounds(sw: southwest, ne: northeast) let bbox = MLNCoordinateBounds(sw: southwest, ne: northeast)
@@ -82,36 +82,36 @@ class MLNDocumentationExampleTests: XCTestCase, MLNMapViewDelegate {
let region = MLNTilePyramidOfflineRegion(styleURL: MLNStyle.lightStyleURL, bounds: bbox, fromZoomLevel: 11, toZoomLevel: 14) let region = MLNTilePyramidOfflineRegion(styleURL: MLNStyle.lightStyleURL, bounds: bbox, fromZoomLevel: 11, toZoomLevel: 14)
let context = "Tile Pyramid Region".data(using: .utf8) let context = "Tile Pyramid Region".data(using: .utf8)
MLNOfflineStorage.shared.addPack(for: region, withContext: context!) MLNOfflineStorage.shared.addPack(for: region, withContext: context!)
//#-end-example-code // #-end-example-code
XCTAssertNotNil(region) XCTAssertNotNil(region)
} }
func testMLNShapeOfflineRegion() { func testMLNShapeOfflineRegion() {
class MLNStyle { class MLNStyle {
static var lightStyleURL: URL { static var lightStyleURL: URL {
return MLNDocumentationExampleTests.styleURL MLNDocumentationExampleTests.styleURL
} }
} }
typealias MLNOfflineStorage = MLNOfflineStorageMock typealias MLNOfflineStorage = MLNOfflineStorageMock
//#-example-code // #-example-code
var coordinates = [ var coordinates = [
CLLocationCoordinate2D(latitude: 45.522585, longitude: -122.685699), CLLocationCoordinate2D(latitude: 45.522585, longitude: -122.685699),
CLLocationCoordinate2D(latitude: 45.534611, longitude: -122.708873), CLLocationCoordinate2D(latitude: 45.534611, longitude: -122.708873),
CLLocationCoordinate2D(latitude: 45.530883, longitude: -122.678833) CLLocationCoordinate2D(latitude: 45.530883, longitude: -122.678833),
] ]
let triangle = MLNPolygon(coordinates: &coordinates, count: UInt(coordinates.count)) let triangle = MLNPolygon(coordinates: &coordinates, count: UInt(coordinates.count))
let region = MLNShapeOfflineRegion(styleURL: MLNStyle.lightStyleURL, shape: triangle, fromZoomLevel: 11, toZoomLevel: 14) let region = MLNShapeOfflineRegion(styleURL: MLNStyle.lightStyleURL, shape: triangle, fromZoomLevel: 11, toZoomLevel: 14)
let context = "Triangle Region".data(using: .utf8) let context = "Triangle Region".data(using: .utf8)
MLNOfflineStorage.shared.addPack(for: region, withContext: context!) MLNOfflineStorage.shared.addPack(for: region, withContext: context!)
//#-end-example-code // #-end-example-code
XCTAssertNotNil(region) XCTAssertNotNil(region)
} }
func testMLNOfflinePack() { func testMLNOfflinePack() {
typealias MLNOfflineStorage = MLNOfflineStorageMock typealias MLNOfflineStorage = MLNOfflineStorageMock
@@ -121,9 +121,9 @@ class MLNDocumentationExampleTests: XCTestCase, MLNMapViewDelegate {
let region = MLNTilePyramidOfflineRegion(styleURL: MLNDocumentationExampleTests.styleURL, bounds: bbox, fromZoomLevel: 11, toZoomLevel: 14) let region = MLNTilePyramidOfflineRegion(styleURL: MLNDocumentationExampleTests.styleURL, bounds: bbox, fromZoomLevel: 11, toZoomLevel: 14)
let context = "Tile Pyramid Region".data(using: .utf8)! let context = "Tile Pyramid Region".data(using: .utf8)!
//#-example-code // #-example-code
MLNOfflineStorage.shared.addPack(for: region, withContext: context) { (pack, error) in MLNOfflineStorage.shared.addPack(for: region, withContext: context) { pack, error in
guard let pack = pack else { guard let pack else {
// If adding the pack fails, log an error to console. // If adding the pack fails, log an error to console.
print("Error:", error?.localizedDescription ?? "unknown error adding pack at \(#file)(\(#line)) in \(#function)") print("Error:", error?.localizedDescription ?? "unknown error adding pack at \(#file)(\(#line)) in \(#function)")
return return
@@ -132,23 +132,23 @@ class MLNDocumentationExampleTests: XCTestCase, MLNMapViewDelegate {
// Start an MLNOfflinePack download // Start an MLNOfflinePack download
pack.resume() pack.resume()
} }
//#-end-example-code // #-end-example-code
} }
func testMLNShape$shapeWithData_encoding_error_() { func testMLNShape$shapeWithData_encoding_error_() {
let mainBundle = Bundle(for: MLNDocumentationExampleTests.self) let mainBundle = Bundle(for: MLNDocumentationExampleTests.self)
//#-example-code // #-example-code
let url = mainBundle.url(forResource: "amsterdam", withExtension: "geojson")! let url = mainBundle.url(forResource: "amsterdam", withExtension: "geojson")!
let data = try! Data(contentsOf: url) let data = try! Data(contentsOf: url)
let feature = try! MLNShape(data: data, encoding: String.Encoding.utf8.rawValue) as! MLNShapeCollectionFeature let feature = try! MLNShape(data: data, encoding: String.Encoding.utf8.rawValue) as! MLNShapeCollectionFeature
//#-end-example-code // #-end-example-code
XCTAssertNotNil(feature.shapes.first as? MLNPolygonFeature) XCTAssertNotNil(feature.shapes.first as? MLNPolygonFeature)
} }
func testMLNShapeSource() { func testMLNShapeSource() {
//#-example-code // #-example-code
var coordinates: [CLLocationCoordinate2D] = [ var coordinates: [CLLocationCoordinate2D] = [
CLLocationCoordinate2D(latitude: 37.77, longitude: -122.42), CLLocationCoordinate2D(latitude: 37.77, longitude: -122.42),
CLLocationCoordinate2D(latitude: 38.91, longitude: -77.04), CLLocationCoordinate2D(latitude: 38.91, longitude: -77.04),
@@ -156,27 +156,27 @@ class MLNDocumentationExampleTests: XCTestCase, MLNMapViewDelegate {
let polyline = MLNPolylineFeature(coordinates: &coordinates, count: UInt(coordinates.count)) let polyline = MLNPolylineFeature(coordinates: &coordinates, count: UInt(coordinates.count))
let source = MLNShapeSource(identifier: "lines", features: [polyline], options: nil) let source = MLNShapeSource(identifier: "lines", features: [polyline], options: nil)
mapView.style?.addSource(source) mapView.style?.addSource(source)
//#-end-example-code // #-end-example-code
XCTAssertNotNil(mapView.style?.source(withIdentifier: "lines")) XCTAssertNotNil(mapView.style?.source(withIdentifier: "lines"))
} }
func testMLNRasterTileSource() { func testMLNRasterTileSource() {
//#-example-code // #-example-code
let source = MLNRasterTileSource(identifier: "clouds", tileURLTemplates: ["https://example.com/raster-tiles/{z}/{x}/{y}.png"], options: [ let source = MLNRasterTileSource(identifier: "clouds", tileURLTemplates: ["https://example.com/raster-tiles/{z}/{x}/{y}.png"], options: [
.minimumZoomLevel: 9, .minimumZoomLevel: 9,
.maximumZoomLevel: 16, .maximumZoomLevel: 16,
.tileSize: 512, .tileSize: 512,
.attributionInfos: [ .attributionInfos: [
MLNAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "https://mapbox.com")) MLNAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "https://mapbox.com")),
] ],
]) ])
mapView.style?.addSource(source) mapView.style?.addSource(source)
//#-end-example-code // #-end-example-code
XCTAssertNotNil(mapView.style?.source(withIdentifier: "clouds")) XCTAssertNotNil(mapView.style?.source(withIdentifier: "clouds"))
} }
func testMLNRasterDEMSource() { func testMLNRasterDEMSource() {
// We want to use mapbox.terrain-rgb in the example, but using a mapbox: // We want to use mapbox.terrain-rgb in the example, but using a mapbox:
// URL requires setting an access token. So this identically named // URL requires setting an access token. So this identically named
@@ -187,53 +187,54 @@ class MLNDocumentationExampleTests: XCTestCase, MLNMapViewDelegate {
super.init(identifier: identifier, configurationURL: bogusURL, tileSize: tileSize) super.init(identifier: identifier, configurationURL: bogusURL, tileSize: tileSize)
} }
} }
//#-example-code // #-example-code
let terrainRGBURL = URL(string: "maptiler://sources/terrain-rgb")! let terrainRGBURL = URL(string: "maptiler://sources/terrain-rgb")!
let source = MLNRasterDEMSource(identifier: "hills", configurationURL: terrainRGBURL) let source = MLNRasterDEMSource(identifier: "hills", configurationURL: terrainRGBURL)
mapView.style?.addSource(source) mapView.style?.addSource(source)
//#-end-example-code // #-end-example-code
XCTAssertNotNil(mapView.style?.source(withIdentifier: "hills")) XCTAssertNotNil(mapView.style?.source(withIdentifier: "hills"))
} }
func testMLNVectorTileSource() { func testMLNVectorTileSource() {
//#-example-code // #-example-code
let source = MLNVectorTileSource(identifier: "pois", tileURLTemplates: ["https://example.com/vector-tiles/{z}/{x}/{y}.mvt"], options: [ let source = MLNVectorTileSource(identifier: "pois", tileURLTemplates: ["https://example.com/vector-tiles/{z}/{x}/{y}.mvt"], options: [
.minimumZoomLevel: 9, .minimumZoomLevel: 9,
.maximumZoomLevel: 16, .maximumZoomLevel: 16,
.attributionInfos: [ .attributionInfos: [
MLNAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "https://mapbox.com")) MLNAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "https://mapbox.com")),
] ],
]) ])
mapView.style?.addSource(source) mapView.style?.addSource(source)
//#-end-example-code // #-end-example-code
XCTAssertNotNil(mapView.style?.source(withIdentifier: "pois")) XCTAssertNotNil(mapView.style?.source(withIdentifier: "pois"))
} }
func testMLNPolyline() { func testMLNPolyline() {
//#-example-code // #-example-code
let coordinates = [ let coordinates = [
CLLocationCoordinate2D(latitude: 35.68476, longitude: -220.24257), CLLocationCoordinate2D(latitude: 35.68476, longitude: -220.24257),
CLLocationCoordinate2D(latitude: 37.78428, longitude: -122.41310) CLLocationCoordinate2D(latitude: 37.78428, longitude: -122.41310),
] ]
let polyline = MLNPolyline(coordinates: coordinates, count: UInt(coordinates.count)) let polyline = MLNPolyline(coordinates: coordinates, count: UInt(coordinates.count))
//#-end-example-code // #-end-example-code
XCTAssertNotNil(polyline) XCTAssertNotNil(polyline)
} }
func testMLNImageSource() { func testMLNImageSource() {
//#-example-code // #-example-code
let coordinates = MLNCoordinateQuad( let coordinates = MLNCoordinateQuad(
topLeft: CLLocationCoordinate2D(latitude: 46.437, longitude: -80.425), topLeft: CLLocationCoordinate2D(latitude: 46.437, longitude: -80.425),
bottomLeft: CLLocationCoordinate2D(latitude: 37.936, longitude: -80.425), bottomLeft: CLLocationCoordinate2D(latitude: 37.936, longitude: -80.425),
bottomRight: CLLocationCoordinate2D(latitude: 37.936, longitude: -71.516), bottomRight: CLLocationCoordinate2D(latitude: 37.936, longitude: -71.516),
topRight: CLLocationCoordinate2D(latitude: 46.437, longitude: -71.516)) topRight: CLLocationCoordinate2D(latitude: 46.437, longitude: -71.516)
)
let source = MLNImageSource(identifier: "radar", coordinateQuad: coordinates, url: URL(string: "https://maplibre.org/maplibre-gl-js-docs/assets/radar.gif")!) let source = MLNImageSource(identifier: "radar", coordinateQuad: coordinates, url: URL(string: "https://maplibre.org/maplibre-gl-js-docs/assets/radar.gif")!)
mapView.style?.addSource(source) mapView.style?.addSource(source)
//#-end-example-code // #-end-example-code
XCTAssertNotNil(mapView.style?.source(withIdentifier: "radar")) XCTAssertNotNil(mapView.style?.source(withIdentifier: "radar"))
} }
@@ -241,8 +242,8 @@ class MLNDocumentationExampleTests: XCTestCase, MLNMapViewDelegate {
func testMLNCircleStyleLayer() { func testMLNCircleStyleLayer() {
let population = MLNVectorTileSource(identifier: "population", configurationURL: URL(string: "https://example.com/style.json")!) let population = MLNVectorTileSource(identifier: "population", configurationURL: URL(string: "https://example.com/style.json")!)
mapView.style?.addSource(population) mapView.style?.addSource(population)
//#-example-code // #-example-code
let layer = MLNCircleStyleLayer(identifier: "circles", source: population) let layer = MLNCircleStyleLayer(identifier: "circles", source: population)
layer.sourceLayerIdentifier = "population" layer.sourceLayerIdentifier = "population"
#if os(macOS) #if os(macOS)
@@ -261,7 +262,7 @@ class MLNDocumentationExampleTests: XCTestCase, MLNMapViewDelegate {
layer.circleOpacity = NSExpression(forConstantValue: 0.7) layer.circleOpacity = NSExpression(forConstantValue: 0.7)
layer.predicate = NSPredicate(format: "%K == %@", "marital-status", "married") layer.predicate = NSPredicate(format: "%K == %@", "marital-status", "married")
mapView.style?.addLayer(layer) mapView.style?.addLayer(layer)
//#-end-example-code // #-end-example-code
XCTAssertNotNil(mapView.style?.layer(withIdentifier: "circles")) XCTAssertNotNil(mapView.style?.layer(withIdentifier: "circles"))
} }
@@ -270,10 +271,10 @@ class MLNDocumentationExampleTests: XCTestCase, MLNMapViewDelegate {
let trails = MLNVectorTileSource(identifier: "trails", configurationURL: URL(string: "https://example.com/style.json")!) let trails = MLNVectorTileSource(identifier: "trails", configurationURL: URL(string: "https://example.com/style.json")!)
mapView.style?.addSource(trails) mapView.style?.addSource(trails)
//#-example-code // #-example-code
let layer = MLNLineStyleLayer(identifier: "trails-path", source: trails) let layer = MLNLineStyleLayer(identifier: "trails-path", source: trails)
layer.sourceLayerIdentifier = "trails" layer.sourceLayerIdentifier = "trails"
let stops = NSExpression(forConstantValue: [14: 2, let stops = NSExpression(forConstantValue: [14: 2,
18: 20]) 18: 20])
layer.lineWidth = NSExpression(forMLNInterpolating: .zoomLevelVariable, layer.lineWidth = NSExpression(forMLNInterpolating: .zoomLevelVariable,
@@ -289,7 +290,7 @@ class MLNDocumentationExampleTests: XCTestCase, MLNMapViewDelegate {
layer.lineCap = NSExpression(forConstantValue: "round") layer.lineCap = NSExpression(forConstantValue: "round")
layer.predicate = NSPredicate(format: "%K == %@", "trail-type", "mountain-biking") layer.predicate = NSPredicate(format: "%K == %@", "trail-type", "mountain-biking")
mapView.style?.addLayer(layer) mapView.style?.addLayer(layer)
//#-end-example-code // #-end-example-code
XCTAssertNotNil(mapView.style?.layer(withIdentifier: "trails-path")) XCTAssertNotNil(mapView.style?.layer(withIdentifier: "trails-path"))
} }
@@ -298,7 +299,7 @@ class MLNDocumentationExampleTests: XCTestCase, MLNMapViewDelegate {
let parks = MLNVectorTileSource(identifier: "parks", configurationURL: URL(string: "https://example.com/style.json")!) let parks = MLNVectorTileSource(identifier: "parks", configurationURL: URL(string: "https://example.com/style.json")!)
mapView.style?.addSource(parks) mapView.style?.addSource(parks)
//#-example-code // #-example-code
let layer = MLNFillStyleLayer(identifier: "parks", source: parks) let layer = MLNFillStyleLayer(identifier: "parks", source: parks)
layer.sourceLayerIdentifier = "parks" layer.sourceLayerIdentifier = "parks"
#if os(macOS) #if os(macOS)
@@ -308,49 +309,49 @@ class MLNDocumentationExampleTests: XCTestCase, MLNMapViewDelegate {
#endif #endif
layer.predicate = NSPredicate(format: "type == %@", "national-park") layer.predicate = NSPredicate(format: "type == %@", "national-park")
mapView.style?.addLayer(layer) mapView.style?.addLayer(layer)
//#-end-example-code // #-end-example-code
XCTAssertNotNil(mapView.style?.layer(withIdentifier: "parks")) XCTAssertNotNil(mapView.style?.layer(withIdentifier: "parks"))
} }
func testMLNFillExtrusionStyleLayer() { func testMLNFillExtrusionStyleLayer() {
let buildings = MLNVectorTileSource(identifier: "buildings", configurationURL: URL(string: "https://example.com/style.json")!) let buildings = MLNVectorTileSource(identifier: "buildings", configurationURL: URL(string: "https://example.com/style.json")!)
mapView.style?.addSource(buildings) mapView.style?.addSource(buildings)
//#-example-code // #-example-code
let layer = MLNFillExtrusionStyleLayer(identifier: "buildings", source: buildings) let layer = MLNFillExtrusionStyleLayer(identifier: "buildings", source: buildings)
layer.sourceLayerIdentifier = "building" layer.sourceLayerIdentifier = "building"
layer.fillExtrusionHeight = NSExpression(forKeyPath: "height") layer.fillExtrusionHeight = NSExpression(forKeyPath: "height")
layer.fillExtrusionBase = NSExpression(forKeyPath: "min_height") layer.fillExtrusionBase = NSExpression(forKeyPath: "min_height")
layer.predicate = NSPredicate(format: "extrude == 'true'") layer.predicate = NSPredicate(format: "extrude == 'true'")
mapView.style?.addLayer(layer) mapView.style?.addLayer(layer)
//#-end-example-code // #-end-example-code
XCTAssertNotNil(mapView.style?.layer(withIdentifier: "buildings")) XCTAssertNotNil(mapView.style?.layer(withIdentifier: "buildings"))
} }
func testMLNHeatmapStyleLayer() { func testMLNHeatmapStyleLayer() {
let earthquakes = MLNShapeSource(identifier: "earthquakes", url: URL(string: "https://example.com/earthquakes.json")!, options: [:]) let earthquakes = MLNShapeSource(identifier: "earthquakes", url: URL(string: "https://example.com/earthquakes.json")!, options: [:])
mapView.style?.addSource(earthquakes) mapView.style?.addSource(earthquakes)
//#-example-code // #-example-code
let layer = MLNHeatmapStyleLayer(identifier: "earthquake-heat", source: earthquakes) let layer = MLNHeatmapStyleLayer(identifier: "earthquake-heat", source: earthquakes)
layer.heatmapWeight = NSExpression(forMLNInterpolating: .zoomLevelVariable, layer.heatmapWeight = NSExpression(forMLNInterpolating: .zoomLevelVariable,
curveType: .linear, curveType: .linear,
parameters: nil, parameters: nil,
stops: NSExpression(forConstantValue: [0: 0, stops: NSExpression(forConstantValue: [0: 0,
6: 1])) 6: 1]))
layer.heatmapIntensity = NSExpression(forMLNInterpolating: .zoomLevelVariable, layer.heatmapIntensity = NSExpression(forMLNInterpolating: .zoomLevelVariable,
curveType: .linear, curveType: .linear,
parameters: nil, parameters: nil,
stops: NSExpression(forConstantValue: [0: 1, stops: NSExpression(forConstantValue: [0: 1,
9: 3])) 9: 3]))
mapView.style?.addLayer(layer) mapView.style?.addLayer(layer)
//#-end-example-code // #-end-example-code
XCTAssertNotNil(mapView.style?.layer(withIdentifier: "earthquake-heat")) XCTAssertNotNil(mapView.style?.layer(withIdentifier: "earthquake-heat"))
} }
@@ -358,7 +359,7 @@ class MLNDocumentationExampleTests: XCTestCase, MLNMapViewDelegate {
let pois = MLNVectorTileSource(identifier: "pois", configurationURL: URL(string: "https://example.com/style.json")!) let pois = MLNVectorTileSource(identifier: "pois", configurationURL: URL(string: "https://example.com/style.json")!)
mapView.style?.addSource(pois) mapView.style?.addSource(pois)
//#-example-code // #-example-code
let layer = MLNSymbolStyleLayer(identifier: "coffeeshops", source: pois) let layer = MLNSymbolStyleLayer(identifier: "coffeeshops", source: pois)
layer.sourceLayerIdentifier = "pois" layer.sourceLayerIdentifier = "pois"
layer.iconImageName = NSExpression(forConstantValue: "coffee") layer.iconImageName = NSExpression(forConstantValue: "coffee")
@@ -374,7 +375,7 @@ class MLNDocumentationExampleTests: XCTestCase, MLNMapViewDelegate {
layer.textAnchor = NSExpression(forConstantValue: "left") layer.textAnchor = NSExpression(forConstantValue: "left")
layer.predicate = NSPredicate(format: "%K == %@", "venue-type", "coffee") layer.predicate = NSPredicate(format: "%K == %@", "venue-type", "coffee")
mapView.style?.addLayer(layer) mapView.style?.addLayer(layer)
//#-end-example-code // #-end-example-code
XCTAssertNotNil(mapView.style?.layer(withIdentifier: "coffeeshops")) XCTAssertNotNil(mapView.style?.layer(withIdentifier: "coffeeshops"))
} }
@@ -385,16 +386,16 @@ class MLNDocumentationExampleTests: XCTestCase, MLNMapViewDelegate {
.maximumZoomLevel: 16, .maximumZoomLevel: 16,
.tileSize: 512, .tileSize: 512,
.attributionInfos: [ .attributionInfos: [
MLNAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "https://mapbox.com")) MLNAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "https://mapbox.com")),
] ],
]) ])
mapView.style?.addSource(source) mapView.style?.addSource(source)
//#-example-code // #-example-code
let layer = MLNRasterStyleLayer(identifier: "clouds", source: source) let layer = MLNRasterStyleLayer(identifier: "clouds", source: source)
layer.rasterOpacity = NSExpression(forConstantValue: 0.5) layer.rasterOpacity = NSExpression(forConstantValue: 0.5)
mapView.style?.addLayer(layer) mapView.style?.addLayer(layer)
//#-end-example-code // #-end-example-code
XCTAssertNotNil(mapView.style?.layer(withIdentifier: "clouds")) XCTAssertNotNil(mapView.style?.layer(withIdentifier: "clouds"))
} }
@@ -405,23 +406,23 @@ class MLNDocumentationExampleTests: XCTestCase, MLNMapViewDelegate {
.maximumZoomLevel: 16, .maximumZoomLevel: 16,
.tileSize: 256, .tileSize: 256,
.attributionInfos: [ .attributionInfos: [
MLNAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "https://mapbox.com")) MLNAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "https://mapbox.com")),
] ],
]) ])
mapView.style?.addSource(source) mapView.style?.addSource(source)
let canals = MLNVectorTileSource(identifier: "canals", configurationURL: URL(string: "https://example.com/style.json")!) let canals = MLNVectorTileSource(identifier: "canals", configurationURL: URL(string: "https://example.com/style.json")!)
mapView.style?.addSource(canals) mapView.style?.addSource(canals)
let canalShadowLayer = MLNLineStyleLayer(identifier: "waterway-river-canal-shadow", source: canals) let canalShadowLayer = MLNLineStyleLayer(identifier: "waterway-river-canal-shadow", source: canals)
mapView.style?.addLayer(canalShadowLayer) mapView.style?.addLayer(canalShadowLayer)
//#-example-code // #-example-code
let layer = MLNHillshadeStyleLayer(identifier: "hills", source: source) let layer = MLNHillshadeStyleLayer(identifier: "hills", source: source)
layer.hillshadeExaggeration = NSExpression(forConstantValue: 0.6) layer.hillshadeExaggeration = NSExpression(forConstantValue: 0.6)
if let canalShadowLayer = mapView.style?.layer(withIdentifier: "waterway-river-canal-shadow") { if let canalShadowLayer = mapView.style?.layer(withIdentifier: "waterway-river-canal-shadow") {
mapView.style?.insertLayer(layer, below: canalShadowLayer) mapView.style?.insertLayer(layer, below: canalShadowLayer)
} }
//#-end-example-code // #-end-example-code
XCTAssertNotNil(mapView.style?.layer(withIdentifier: "hills")) XCTAssertNotNil(mapView.style?.layer(withIdentifier: "hills"))
} }
@@ -430,22 +431,22 @@ class MLNDocumentationExampleTests: XCTestCase, MLNMapViewDelegate {
let terrain = MLNVectorTileSource(identifier: "terrain", configurationURL: URL(string: "https://example.com/style.json")!) let terrain = MLNVectorTileSource(identifier: "terrain", configurationURL: URL(string: "https://example.com/style.json")!)
mapView.style?.addSource(terrain) mapView.style?.addSource(terrain)
//#-example-code // #-example-code
let layer = MLNLineStyleLayer(identifier: "contour", source: terrain) let layer = MLNLineStyleLayer(identifier: "contour", source: terrain)
layer.sourceLayerIdentifier = "contours" layer.sourceLayerIdentifier = "contours"
layer.predicate = NSPredicate(format: "(index == 5 || index == 10) && CAST(ele, 'NSNumber') >= 1500.0") layer.predicate = NSPredicate(format: "(index == 5 || index == 10) && CAST(ele, 'NSNumber') >= 1500.0")
mapView.style?.addLayer(layer) mapView.style?.addLayer(layer)
//#-end-example-code // #-end-example-code
XCTAssertNotNil(mapView.style?.layer(withIdentifier: "contour")) XCTAssertNotNil(mapView.style?.layer(withIdentifier: "contour"))
} }
func testMLNMapView() { func testMLNMapView() {
//#-example-code // #-example-code
#if os(macOS) #if os(macOS)
class MapClickGestureRecognizer: NSClickGestureRecognizer { class MapClickGestureRecognizer: NSClickGestureRecognizer {
override func shouldRequireFailure(of otherGestureRecognizer: NSGestureRecognizer) -> Bool { override func shouldRequireFailure(of otherGestureRecognizer: NSGestureRecognizer) -> Bool {
return otherGestureRecognizer is NSClickGestureRecognizer otherGestureRecognizer is NSClickGestureRecognizer
} }
} }
#else #else
@@ -455,13 +456,13 @@ class MLNDocumentationExampleTests: XCTestCase, MLNMapViewDelegate {
} }
mapView.addGestureRecognizer(mapTapGestureRecognizer) mapView.addGestureRecognizer(mapTapGestureRecognizer)
#endif #endif
//#-end-example-code // #-end-example-code
} }
func testMLNMapSnapshotter() throws { func testMLNMapSnapshotter() throws {
throw XCTSkip("Snapshotter not implemented yet for Metal. See https://github.com/maplibre/maplibre-native/issues/1862") throw XCTSkip("Snapshotter not implemented yet for Metal. See https://github.com/maplibre/maplibre-native/issues/1862")
let expectation = self.expectation(description: "MLNMapSnapshotter should produce a snapshot") let expectation = expectation(description: "MLNMapSnapshotter should produce a snapshot")
#if os(macOS) #if os(macOS)
var image: NSImage? { var image: NSImage? {
didSet { didSet {
@@ -475,138 +476,136 @@ class MLNDocumentationExampleTests: XCTestCase, MLNMapViewDelegate {
} }
} }
#endif #endif
class MLNStyle { class MLNStyle {
static var satelliteStreetsStyleURL: URL { static var satelliteStreetsStyleURL: URL {
return MLNDocumentationExampleTests.styleURL MLNDocumentationExampleTests.styleURL
} }
} }
//#-example-code // #-example-code
let camera = MLNMapCamera(lookingAtCenter: CLLocationCoordinate2D(latitude: 37.7184, longitude: -122.4365), altitude: 100, pitch: 20, heading: 0) let camera = MLNMapCamera(lookingAtCenter: CLLocationCoordinate2D(latitude: 37.7184, longitude: -122.4365), altitude: 100, pitch: 20, heading: 0)
let options = MLNMapSnapshotOptions(styleURL: MLNStyle.satelliteStreetsStyleURL, camera: camera, size: CGSize(width: 320, height: 480)) let options = MLNMapSnapshotOptions(styleURL: MLNStyle.satelliteStreetsStyleURL, camera: camera, size: CGSize(width: 320, height: 480))
options.zoomLevel = 10 options.zoomLevel = 10
let snapshotter = MLNMapSnapshotter(options: options) let snapshotter = MLNMapSnapshotter(options: options)
snapshotter.start { (snapshot, error) in snapshotter.start { snapshot, error in
if let error = error { if let error {
fatalError(error.localizedDescription) fatalError(error.localizedDescription)
} }
image = snapshot?.image image = snapshot?.image
} }
//#-end-example-code // #-end-example-code
wait(for: [expectation], timeout: 5) wait(for: [expectation], timeout: 5)
_ = image _ = image
} }
func testMLNCluster() {
func testMLNCluster() {
enum ExampleError: Error { enum ExampleError: Error {
case unexpectedFeatureType case unexpectedFeatureType
case featureIsNotACluster case featureIsNotACluster
} }
let geoJSON: [String: Any] = [ let geoJSON: [String: Any] = [
"type" : "Feature", "type": "Feature",
"geometry" : [ "geometry": [
"coordinates" : [ "coordinates": [
-77.00896639534831, -77.00896639534831,
38.87031006108791, 38.87031006108791,
0.0 0.0,
], ],
"type" : "Point" "type": "Point",
] as [String : Any], ] as [String: Any],
"properties" : [ "properties": [
"cluster" : true, "cluster": true,
"cluster_id" : 123, "cluster_id": 123,
"point_count" : 4567, "point_count": 4567,
] as [String : Any] ] as [String: Any],
] ]
let clusterShapeData = try! JSONSerialization.data(withJSONObject: geoJSON, options: []) let clusterShapeData = try! JSONSerialization.data(withJSONObject: geoJSON, options: [])
do { do {
//#-example-code // #-example-code
let shape = try! MLNShape(data: clusterShapeData, encoding: String.Encoding.utf8.rawValue) let shape = try! MLNShape(data: clusterShapeData, encoding: String.Encoding.utf8.rawValue)
guard let pointFeature = shape as? MLNPointFeature else { guard let pointFeature = shape as? MLNPointFeature else {
throw ExampleError.unexpectedFeatureType throw ExampleError.unexpectedFeatureType
} }
// Check for cluster conformance // Check for cluster conformance
guard let cluster = pointFeature as? MLNCluster else { guard let cluster = pointFeature as? MLNCluster else {
throw ExampleError.featureIsNotACluster throw ExampleError.featureIsNotACluster
} }
// Currently the only supported class that conforms to `MLNCluster` is // Currently the only supported class that conforms to `MLNCluster` is
// `MLNPointFeatureCluster` // `MLNPointFeatureCluster`
guard cluster is MLNPointFeatureCluster else { guard cluster is MLNPointFeatureCluster else {
throw ExampleError.unexpectedFeatureType throw ExampleError.unexpectedFeatureType
} }
//#-end-example-code // #-end-example-code
XCTAssert(cluster.clusterIdentifier == 123) XCTAssert(cluster.clusterIdentifier == 123)
XCTAssert(cluster.clusterPointCount == 4567) XCTAssert(cluster.clusterPointCount == 4567)
} } catch {
catch let error {
XCTFail("Example failed with thrown error: \(error)") XCTFail("Example failed with thrown error: \(error)")
} }
} }
func testMLNAttributedExpression() { func testMLNAttributedExpression() {
//#-example-code // #-example-code
#if os(macOS) #if os(macOS)
let redColor = NSColor.red let redColor = NSColor.red
#else #else
let redColor = UIColor.red let redColor = UIColor.red
#endif #endif
let expression = NSExpression(forConstantValue: "Foo") let expression = NSExpression(forConstantValue: "Foo")
let attributes: [MLNAttributedExpressionKey: NSExpression] = [.fontNamesAttribute : NSExpression(forConstantValue: ["DIN Offc Pro Italic", let attributes: [MLNAttributedExpressionKey: NSExpression] = [.fontNamesAttribute: NSExpression(forConstantValue: ["DIN Offc Pro Italic",
"Arial Unicode MS Regular"]), "Arial Unicode MS Regular"]),
.fontScaleAttribute: NSExpression(forConstantValue: 1.2), .fontScaleAttribute: NSExpression(forConstantValue: 1.2),
.fontColorAttribute: NSExpression(forConstantValue: redColor)] .fontColorAttribute: NSExpression(forConstantValue: redColor)]
let attributedExpression = MLNAttributedExpression(expression, attributes:attributes) let attributedExpression = MLNAttributedExpression(expression, attributes: attributes)
//#-end-example-code // #-end-example-code
XCTAssertNotNil(attributedExpression) XCTAssertNotNil(attributedExpression)
} }
func testMLNShapeSourceOptionClusterProperties() { func testMLNShapeSourceOptionClusterProperties() {
//#-example-code // #-example-code
let firstExpression = NSExpression(format: "sum:({$featureAccumulated, sumValue})") let firstExpression = NSExpression(format: "sum:({$featureAccumulated, sumValue})")
let secondExpression = NSExpression(forKeyPath: "magnitude") let secondExpression = NSExpression(forKeyPath: "magnitude")
let clusterPropertiesDictionary = ["sumValue" : [firstExpression, secondExpression]] let clusterPropertiesDictionary = ["sumValue": [firstExpression, secondExpression]]
let options : [MLNShapeSourceOption : Any] = [.clustered : true, let options: [MLNShapeSourceOption: Any] = [.clustered: true,
.clusterProperties: clusterPropertiesDictionary] .clusterProperties: clusterPropertiesDictionary]
//#-end-example-code // #-end-example-code
let geoJSON: [String: Any] = [ let geoJSON: [String: Any] = [
"type" : "Feature", "type": "Feature",
"geometry" : [ "geometry": [
"coordinates" : [ "coordinates": [
-77.00896639534831, -77.00896639534831,
38.87031006108791, 38.87031006108791,
0.0 0.0,
], ],
"type" : "Point" "type": "Point",
] as [String : Any], ] as [String: Any],
"properties" : [ "properties": [
"cluster" : true, "cluster": true,
"cluster_id" : 123, "cluster_id": 123,
"point_count" : 4567, "point_count": 4567,
] as [String : Any] ] as [String: Any],
] ]
let clusterShapeData = try! JSONSerialization.data(withJSONObject: geoJSON, options: []) let clusterShapeData = try! JSONSerialization.data(withJSONObject: geoJSON, options: [])
let shape = try! MLNShape(data: clusterShapeData, encoding: String.Encoding.utf8.rawValue) let shape = try! MLNShape(data: clusterShapeData, encoding: String.Encoding.utf8.rawValue)
let source = MLNShapeSource(identifier: "source", shape: shape, options: options) let source = MLNShapeSource(identifier: "source", shape: shape, options: options)
mapView.style?.addSource(source) mapView.style?.addSource(source)
} }
// For testMLNMapView(). // For testMLNMapView().
func myCustomFunction() {} func myCustomFunction() {}
} }

View File

@@ -1,5 +1,5 @@
import XCTest
import MapLibre import MapLibre
import XCTest
/** /**
Test cases that ensure the inline examples in the jazzy guides compile. Test cases that ensure the inline examples in the jazzy guides compile.
@@ -24,7 +24,7 @@ import MapLibre
class MLNDocumentationGuideTests: XCTestCase, MLNMapViewDelegate { class MLNDocumentationGuideTests: XCTestCase, MLNMapViewDelegate {
var mapView: MLNMapView! var mapView: MLNMapView!
var styleLoadingExpectation: XCTestExpectation! var styleLoadingExpectation: XCTestExpectation!
override func setUp() { override func setUp() {
super.setUp() super.setUp()
let styleURL = Bundle(for: MLNDocumentationGuideTests.self).url(forResource: "one-liner", withExtension: "json") let styleURL = Bundle(for: MLNDocumentationGuideTests.self).url(forResource: "one-liner", withExtension: "json")
@@ -33,19 +33,19 @@ class MLNDocumentationGuideTests: XCTestCase, MLNMapViewDelegate {
styleLoadingExpectation = expectation(description: "Map view should finish loading style") styleLoadingExpectation = expectation(description: "Map view should finish loading style")
waitForExpectations(timeout: 10, handler: nil) waitForExpectations(timeout: 10, handler: nil)
} }
override func tearDown() { override func tearDown() {
mapView = nil mapView = nil
styleLoadingExpectation = nil styleLoadingExpectation = nil
super.tearDown() super.tearDown()
} }
func mapView(_ mapView: MLNMapView, didFinishLoading style: MLNStyle) { func mapView(_: MLNMapView, didFinishLoading _: MLNStyle) {
styleLoadingExpectation.fulfill() styleLoadingExpectation.fulfill()
} }
func testMigratingToExpressions$Stops() { func testMigratingToExpressions$Stops() {
//#-example-code // #-example-code
// Swift sample on how to populate a stepping expression with multiple stops. // Swift sample on how to populate a stepping expression with multiple stops.
// Create a color ramp. // Create a color ramp.
#if os(macOS) #if os(macOS)
@@ -76,28 +76,29 @@ class MLNDocumentationGuideTests: XCTestCase, MLNMapViewDelegate {
let stopsLineWidth = [ let stopsLineWidth = [
11.0: initialValue, 11.0: initialValue,
14.0: 6.0, 14.0: 6.0,
20.0: 18.0] 20.0: 18.0,
]
functionExpression = NSExpression( functionExpression = NSExpression(
forMLNStepping: .zoomLevelVariable, forMLNStepping: .zoomLevelVariable,
from: NSExpression(forConstantValue: initialValue), from: NSExpression(forConstantValue: initialValue),
stops: NSExpression(forConstantValue: stopsLineWidth) stops: NSExpression(forConstantValue: stopsLineWidth)
) )
//#-end-example-code // #-end-example-code
print(functionExpression) print(functionExpression)
print(stopsLineWidth) print(stopsLineWidth)
} }
func testMigratingToExpressions$Linear() { func testMigratingToExpressions$Linear() {
//#-example-code // #-example-code
let url = URL(string: "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.geojson")! let url = URL(string: "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.geojson")!
let symbolSource = MLNSource(identifier: "source") let symbolSource = MLNSource(identifier: "source")
let symbolLayer = MLNSymbolStyleLayer(identifier: "place-city-sm", source: symbolSource) let symbolLayer = MLNSymbolStyleLayer(identifier: "place-city-sm", source: symbolSource)
let source = MLNShapeSource(identifier: "earthquakes", url: url, options: nil) let source = MLNShapeSource(identifier: "earthquakes", url: url, options: nil)
let mag = 1.0 // Update based on earthquake GeoJSON data let mag = 1.0 // Update based on earthquake GeoJSON data
mapView.style?.addSource(source) mapView.style?.addSource(source)
#if os(macOS) #if os(macOS)
let stops: [NSNumber: NSColor] = [ let stops: [NSNumber: NSColor] = [
0: .yellow, 0: .yellow,
@@ -115,97 +116,36 @@ class MLNDocumentationGuideTests: XCTestCase, MLNMapViewDelegate {
10: .white, 10: .white,
] ]
#endif #endif
let layer = MLNCircleStyleLayer(identifier: "circles", source: source) let layer = MLNCircleStyleLayer(identifier: "circles", source: source)
let circleExpression : NSExpression let circleExpression: NSExpression
if #available(iOS 15, *) { if #available(iOS 15, *) {
circleExpression = NSExpression( circleExpression = NSExpression(
forMLNInterpolating: NSExpression(forConstantValue: mag), forMLNInterpolating: NSExpression(forConstantValue: mag),
curveType: .linear, curveType: .linear,
parameters: nil, parameters: nil,
stops: NSExpression(forConstantValue: stops)) stops: NSExpression(forConstantValue: stops)
)
} else { } else {
// This works up to iOS 14.5 // This works up to iOS 14.5
circleExpression = NSExpression( circleExpression = NSExpression(
format: "mgl_interpolate:withCurveType:parameters:stops:(mag, 'linear', nil, %@)", format: "mgl_interpolate:withCurveType:parameters:stops:(mag, 'linear', nil, %@)",
stops) stops
)
} }
layer.circleColor = circleExpression layer.circleColor = circleExpression
layer.circleRadius = NSExpression(forConstantValue: 10) layer.circleRadius = NSExpression(forConstantValue: 10)
mapView.style?.insertLayer(layer, below: symbolLayer) mapView.style?.insertLayer(layer, below: symbolLayer)
//#-end-example-code // #-end-example-code
print(circleExpression) print(circleExpression)
} }
func testMigratingToExpressions$LinearConvenience() { func testMigratingToExpressions$LinearConvenience() {
let source = MLNShapeSource(identifier: "circles", shape: nil, options: nil) let source = MLNShapeSource(identifier: "circles", shape: nil, options: nil)
let layer = MLNCircleStyleLayer(identifier: "circles", source: source) let layer = MLNCircleStyleLayer(identifier: "circles", source: source)
#if os(macOS)
let stops: [NSNumber: NSColor] = [
0: .yellow,
2.5: .orange,
5: .red,
7.5: .blue,
10: .white,
]
#else
let stops: [NSNumber: UIColor] = [
0: .yellow,
2.5: .orange,
5: .red,
7.5: .blue,
10: .white,
]
#endif
//#-example-code
layer.circleColor = NSExpression(forMLNInterpolating: NSExpression(forKeyPath: "mag"), curveType: .linear, parameters: nil, stops: NSExpression(forConstantValue: stops))
//#-end-example-code
layer.circleRadius = NSExpression(forConstantValue: 10)
mapView.style?.addLayer(layer)
}
func testMigratingToExpressions$Exponential() {
let source = MLNShapeSource(identifier: "circles", shape: nil, options: nil)
let layer = MLNCircleStyleLayer(identifier: "circles", source: source)
//#-example-code
let stops = [
12: 0.5,
14: 2,
18: 18,
]
layer.circleRadius = NSExpression(forMLNInterpolating: .zoomLevelVariable,
curveType: .exponential,
parameters: NSExpression(forConstantValue: 1.5),
stops: NSExpression(forConstantValue: stops))
//#-end-example-code
}
func testMigratingToExpressions$ExponentialConvenience() {
let source = MLNShapeSource(identifier: "circles", shape: nil, options: nil)
let layer = MLNCircleStyleLayer(identifier: "circles", source: source)
//#-example-code
let stops = [
12: 0.5,
14: 2,
18: 18,
]
layer.circleRadius = NSExpression(forMLNInterpolating: NSExpression.zoomLevelVariable, curveType: MLNExpressionInterpolationMode.exponential, parameters: NSExpression(forConstantValue: 1.5), stops: NSExpression(forConstantValue: stops))
//#-end-example-code
}
func testMigratingToExpressions$Interval() {
let source = MLNShapeSource(identifier: "circles", shape: nil, options: nil)
let layer = MLNCircleStyleLayer(identifier: "circles", source: source)
//#-example-code
#if os(macOS) #if os(macOS)
let stops: [NSNumber: NSColor] = [ let stops: [NSNumber: NSColor] = [
0: .yellow, 0: .yellow,
@@ -214,7 +154,71 @@ class MLNDocumentationGuideTests: XCTestCase, MLNMapViewDelegate {
7.5: .blue, 7.5: .blue,
10: .white, 10: .white,
] ]
#else
let stops: [NSNumber: UIColor] = [
0: .yellow,
2.5: .orange,
5: .red,
7.5: .blue,
10: .white,
]
#endif
// #-example-code
layer.circleColor = NSExpression(forMLNInterpolating: NSExpression(forKeyPath: "mag"), curveType: .linear, parameters: nil, stops: NSExpression(forConstantValue: stops))
// #-end-example-code
layer.circleRadius = NSExpression(forConstantValue: 10)
mapView.style?.addLayer(layer)
}
func testMigratingToExpressions$Exponential() {
let source = MLNShapeSource(identifier: "circles", shape: nil, options: nil)
let layer = MLNCircleStyleLayer(identifier: "circles", source: source)
// #-example-code
let stops = [
12: 0.5,
14: 2,
18: 18,
]
layer.circleRadius = NSExpression(forMLNInterpolating: .zoomLevelVariable,
curveType: .exponential,
parameters: NSExpression(forConstantValue: 1.5),
stops: NSExpression(forConstantValue: stops))
// #-end-example-code
}
func testMigratingToExpressions$ExponentialConvenience() {
let source = MLNShapeSource(identifier: "circles", shape: nil, options: nil)
let layer = MLNCircleStyleLayer(identifier: "circles", source: source)
// #-example-code
let stops = [
12: 0.5,
14: 2,
18: 18,
]
layer.circleRadius = NSExpression(forMLNInterpolating: NSExpression.zoomLevelVariable, curveType: MLNExpressionInterpolationMode.exponential, parameters: NSExpression(forConstantValue: 1.5), stops: NSExpression(forConstantValue: stops))
// #-end-example-code
}
func testMigratingToExpressions$Interval() {
let source = MLNShapeSource(identifier: "circles", shape: nil, options: nil)
let layer = MLNCircleStyleLayer(identifier: "circles", source: source)
// #-example-code
#if os(macOS)
let stops: [NSNumber: NSColor] = [
0: .yellow,
2.5: .orange,
5: .red,
7.5: .blue,
10: .white,
]
layer.circleColor = NSExpression(forMLNStepping: .zoomLevelVariable, layer.circleColor = NSExpression(forMLNStepping: .zoomLevelVariable,
from: NSExpression(forConstantValue: NSColor.green), from: NSExpression(forConstantValue: NSColor.green),
stops: NSExpression(forConstantValue: stops)) stops: NSExpression(forConstantValue: stops))
@@ -226,19 +230,19 @@ class MLNDocumentationGuideTests: XCTestCase, MLNMapViewDelegate {
7.5: .blue, 7.5: .blue,
10: .white, 10: .white,
] ]
layer.circleColor = NSExpression(forMLNStepping: .zoomLevelVariable, layer.circleColor = NSExpression(forMLNStepping: .zoomLevelVariable,
from: NSExpression(forConstantValue: UIColor.green), from: NSExpression(forConstantValue: UIColor.green),
stops: NSExpression(forConstantValue: stops)) stops: NSExpression(forConstantValue: stops))
#endif #endif
//#-end-example-code // #-end-example-code
} }
func testMigratingToExpressions$Categorical() { func testMigratingToExpressions$Categorical() {
let source = MLNShapeSource(identifier: "circles", shape: nil, options: nil) let source = MLNShapeSource(identifier: "circles", shape: nil, options: nil)
let layer = MLNCircleStyleLayer(identifier: "circles", source: source) let layer = MLNCircleStyleLayer(identifier: "circles", source: source)
//#-example-code // #-example-code
// Category type // Category type
let type = NSExpression(forConstantValue: "type") let type = NSExpression(forConstantValue: "type")
@@ -248,81 +252,83 @@ class MLNDocumentationGuideTests: XCTestCase, MLNMapViewDelegate {
let quarryBlast = NSExpression(forConstantValue: "quarry blast") let quarryBlast = NSExpression(forConstantValue: "quarry blast")
#if os(macOS) #if os(macOS)
let defaultColor = NSExpression(forConstantValue: NSColor.blue) let defaultColor = NSExpression(forConstantValue: NSColor.blue)
let orange = NSExpression(forConstantValue: NSColor.orange) let orange = NSExpression(forConstantValue: NSColor.orange)
let red = NSExpression(forConstantValue: NSColor.red) let red = NSExpression(forConstantValue: NSColor.red)
let yellow = NSExpression(forConstantValue: NSColor.yellow) let yellow = NSExpression(forConstantValue: NSColor.yellow)
layer.circleColor = NSExpression(forMLNMatchingKey: type, layer.circleColor = NSExpression(forMLNMatchingKey: type,
in: [earthquake:orange, explosion:red, quarryBlast:yellow], in: [earthquake: orange, explosion: red, quarryBlast: yellow],
default: defaultColor) default: defaultColor)
#else #else
let defaultColor = NSExpression(forConstantValue: UIColor.blue) let defaultColor = NSExpression(forConstantValue: UIColor.blue)
let orange = NSExpression(forConstantValue: UIColor.orange) let orange = NSExpression(forConstantValue: UIColor.orange)
let red = NSExpression(forConstantValue: UIColor.red) let red = NSExpression(forConstantValue: UIColor.red)
let yellow = NSExpression(forConstantValue: UIColor.yellow) let yellow = NSExpression(forConstantValue: UIColor.yellow)
XCTExpectFailure("Awaiting unit test refactoring for https://github.com/maplibre/maplibre-native/issues/331")
XCTExpectFailure("Awaiting unit test refactoring for https://github.com/maplibre/maplibre-native/issues/331") layer.circleColor = NSExpression(forMLNMatchingKey: type,
layer.circleColor = NSExpression(forMLNMatchingKey: type, in: [earthquake: orange, explosion: red, quarryBlast: yellow],
in: [earthquake:orange, explosion:red, quarryBlast:yellow], default: defaultColor)
default: defaultColor)
#endif #endif
//#-end-example-code // #-end-example-code
} }
func testMigratingToExpressions$CategoricalValue() { func testMigratingToExpressions$CategoricalValue() {
let source = MLNShapeSource(identifier: "circles", shape: nil, options: nil) let source = MLNShapeSource(identifier: "circles", shape: nil, options: nil)
let layer = MLNCircleStyleLayer(identifier: "circles", source: source) let layer = MLNCircleStyleLayer(identifier: "circles", source: source)
//#-example-code // #-example-code
#if os(macOS) #if os(macOS)
let stops : [String : NSColor] = ["earthquake" : NSColor.orange, let stops: [String: NSColor] = ["earthquake": NSColor.orange,
"explosion" : NSColor.red, "explosion": NSColor.red,
"quarry blast" : NSColor.yellow] "quarry blast": NSColor.yellow]
layer.circleColor = NSExpression( layer.circleColor = NSExpression(
format: "FUNCTION(%@, 'valueForKeyPath:', type)", format: "FUNCTION(%@, 'valueForKeyPath:', type)",
stops) stops
)
#else #else
let stops : [String : UIColor] = ["earthquake" : UIColor.orange, let stops: [String: UIColor] = ["earthquake": UIColor.orange,
"explosion" : UIColor.red, "explosion": UIColor.red,
"quarry blast" : UIColor.yellow] "quarry blast": UIColor.yellow]
layer.circleColor = NSExpression( layer.circleColor = NSExpression(
format: "FUNCTION(%@, 'valueForKeyPath:', type)", format: "FUNCTION(%@, 'valueForKeyPath:', type)",
stops) stops
)
#endif #endif
//#-end-example-code // #-end-example-code
} }
func testMigratingToExpressions$Identity() { func testMigratingToExpressions$Identity() {
let source = MLNShapeSource(identifier: "circles", shape: nil, options: nil) let source = MLNShapeSource(identifier: "circles", shape: nil, options: nil)
let layer = MLNCircleStyleLayer(identifier: "circles", source: source) let layer = MLNCircleStyleLayer(identifier: "circles", source: source)
//#-example-code // #-example-code
layer.circleRadius = NSExpression(forKeyPath: "mag") layer.circleRadius = NSExpression(forKeyPath: "mag")
//#-end-example-code // #-end-example-code
} }
func testMigratingToExpressions$Multiply() { func testMigratingToExpressions$Multiply() {
let source = MLNShapeSource(identifier: "circles", shape: nil, options: nil) let source = MLNShapeSource(identifier: "circles", shape: nil, options: nil)
let layer = MLNCircleStyleLayer(identifier: "circles", source: source) let layer = MLNCircleStyleLayer(identifier: "circles", source: source)
//#-example-code // #-example-code
layer.circleRadius = NSExpression(forFunction: "multiply:by:", arguments: [NSExpression(forKeyPath: "mag"), 3]) layer.circleRadius = NSExpression(forFunction: "multiply:by:", arguments: [NSExpression(forKeyPath: "mag"), 3])
//#-end-example-code // #-end-example-code
} }
func testMigratingToExpressions$Cast() { func testMigratingToExpressions$Cast() {
let source = MLNShapeSource(identifier: "circles", shape: nil, options: nil) let source = MLNShapeSource(identifier: "circles", shape: nil, options: nil)
//#-example-code // #-example-code
let magnitudeLayer = MLNSymbolStyleLayer(identifier: "mag-layer", source: source) let magnitudeLayer = MLNSymbolStyleLayer(identifier: "mag-layer", source: source)
magnitudeLayer.text = NSExpression(format: "CAST(mag, 'NSString')") magnitudeLayer.text = NSExpression(format: "CAST(mag, 'NSString')")
mapView.style?.addLayer(magnitudeLayer) mapView.style?.addLayer(magnitudeLayer)
//#-end-example-code // #-end-example-code
} }
// MARK: Swift Example Code for Expected Failures // MARK: Swift Example Code for Expected Failures
func testExpectPassSwift() { func testExpectPassSwift() {
XCTAssertNotNil(1) XCTAssertNotNil(1)
} }

View File

@@ -1,10 +1,9 @@
import XCTest import XCTest
class MLNSDKTestHelpers { class MLNSDKTestHelpers {
class func checkTestsContainAllMethods(testClass: Swift.AnyClass, in p: Protocol) { class func checkTestsContainAllMethods(testClass: Swift.AnyClass, in p: Protocol) {
let testMethods = self.classMethodDescriptions(testClass) let testMethods = classMethodDescriptions(testClass)
let subjectMethods = self.protocolMethodDescriptions(p) let subjectMethods = protocolMethodDescriptions(p)
for method in subjectMethods { for method in subjectMethods {
if !testMethods.contains(method) { if !testMethods.contains(method) {
@@ -14,16 +13,14 @@ class MLNSDKTestHelpers {
XCTAssert(true) XCTAssert(true)
} }
} }
extension MLNSDKTestHelpers { extension MLNSDKTestHelpers {
class func protocolMethodDescriptions(_ p: Protocol) -> Set<String> { class func protocolMethodDescriptions(_ p: Protocol) -> Set<String> {
var methods = Set<String>() var methods = Set<String>()
var methodCount = UInt32() var methodCount = UInt32()
let methodDescriptionList = protocol_copyMethodDescriptionList(p, false, true, &methodCount) let methodDescriptionList = protocol_copyMethodDescriptionList(p, false, true, &methodCount)
for i in 0..<Int(methodCount) { for i in 0 ..< Int(methodCount) {
let description = methodDescriptionList![i] let description = methodDescriptionList![i]
XCTAssertNotNil(description.name?.description) XCTAssertNotNil(description.name?.description)
methods.insert(description.name!.description) methods.insert(description.name!.description)
@@ -36,7 +33,7 @@ extension MLNSDKTestHelpers {
var methods = Set<String>() var methods = Set<String>()
var methodCount = UInt32() var methodCount = UInt32()
let methodList = class_copyMethodList(cls, &methodCount) let methodList = class_copyMethodList(cls, &methodCount)
for i in 0..<Int(methodCount) { for i in 0 ..< Int(methodCount) {
let method = methodList![i] let method = methodList![i]
let selector = method_getName(method) let selector = method_getName(method)
methods.insert(selector.description) methods.insert(selector.description)
@@ -44,5 +41,4 @@ extension MLNSDKTestHelpers {
free(methodList) free(methodList)
return methods return methods
} }
} }

View File

@@ -1,45 +1,43 @@
import XCTest import XCTest
class MLNSourceTests: MLNMapViewIntegrationTest { class MLNSourceTests: MLNMapViewIntegrationTest {
// See testForRaisingExceptionsOnStaleStyleObjects for Obj-C sibling. // See testForRaisingExceptionsOnStaleStyleObjects for Obj-C sibling.
func testForRaisingExceptionsOnStaleStyleObjectsOnRemoveFromMapView() { func testForRaisingExceptionsOnStaleStyleObjectsOnRemoveFromMapView() {
guard guard
let configURL = URL(string: "mapbox://examples.2uf7qges") else { let configURL = URL(string: "mapbox://examples.2uf7qges")
XCTFail() else {
return XCTFail()
return
} }
let source = MLNVectorTileSource(identifier: "trees", configurationURL: configURL) let source = MLNVectorTileSource(identifier: "trees", configurationURL: configURL)
mapView.style?.addSource(source) mapView.style?.addSource(source)
let bundle = Bundle(for: type(of: self)) let bundle = Bundle(for: type(of: self))
guard let styleURL = bundle.url(forResource: "one-liner", withExtension: "json") else { guard let styleURL = bundle.url(forResource: "one-liner", withExtension: "json") else {
XCTFail() XCTFail()
return return
} }
styleLoadingExpectation = nil;
mapView.centerCoordinate = CLLocationCoordinate2D(latitude : 38.897, longitude : -77.039) styleLoadingExpectation = nil
mapView.zoomLevel = 10.5
mapView.styleURL = styleURL mapView.centerCoordinate = CLLocationCoordinate2D(latitude: 38.897, longitude: -77.039)
mapView.zoomLevel = 10.5
mapView.styleURL = styleURL
waitForMapViewToFinishLoadingStyle(withTimeout: 10.0) waitForMapViewToFinishLoadingStyle(withTimeout: 10.0)
let expect = expectation(description: "Remove source should error") let expect = expectation(description: "Remove source should error")
do { do {
try mapView.style?.removeSource(source, error: ()) try mapView.style?.removeSource(source, error: ())
} } catch let error as NSError {
catch let error as NSError {
XCTAssertEqual(error.domain, MLNErrorDomain) XCTAssertEqual(error.domain, MLNErrorDomain)
XCTAssertEqual(error.code, MLNErrorCode.sourceCannotBeRemovedFromStyle.rawValue) XCTAssertEqual(error.code, MLNErrorCode.sourceCannotBeRemovedFromStyle.rawValue)
expect.fulfill() expect.fulfill()
} }
wait(for: [expect], timeout: 0.1) wait(for: [expect], timeout: 0.1)
} }
} }

View File

@@ -1,21 +1,20 @@
import XCTest import XCTest
class MLNMapSnapshotterSwiftTests: MLNMapViewIntegrationTest { class MLNMapSnapshotterSwiftTests: MLNMapViewIntegrationTest {
// Create snapshot options // Create snapshot options
private class func snapshotterOptions(size: CGSize) -> MLNMapSnapshotOptions { private class func snapshotterOptions(size: CGSize) -> MLNMapSnapshotOptions {
let camera = MLNMapCamera() let camera = MLNMapCamera()
let options = MLNMapSnapshotOptions(styleURL: MLNStyle.predefinedStyle("Hybrid").url , camera: camera, size: size) let options = MLNMapSnapshotOptions(styleURL: MLNStyle.predefinedStyle("Hybrid").url, camera: camera, size: size)
let sw = CLLocationCoordinate2D(latitude: 52.3, longitude: 13.0) let sw = CLLocationCoordinate2D(latitude: 52.3, longitude: 13.0)
let ne = CLLocationCoordinate2D(latitude: 52.5, longitude: 13.2) let ne = CLLocationCoordinate2D(latitude: 52.5, longitude: 13.2)
options.coordinateBounds = MLNCoordinateBounds(sw:sw, ne:ne) options.coordinateBounds = MLNCoordinateBounds(sw: sw, ne: ne)
return options return options
} }
public override func setUp() { override public func setUp() {
super.setUp() super.setUp()
MLNSettings.use(MLNWellKnownTileServer.mapTiler) MLNSettings.use(MLNWellKnownTileServer.mapTiler)
} }
@@ -25,7 +24,7 @@ class MLNMapSnapshotterSwiftTests: MLNMapViewIntegrationTest {
// This Swift test, is essentially the same except for capturing the snapshotter // This Swift test, is essentially the same except for capturing the snapshotter
let timeout: TimeInterval = 10.0 let timeout: TimeInterval = 10.0
let expectation = self.expectation(description: "snapshot") let expectation = expectation(description: "snapshot")
let options = MLNMapSnapshotterSwiftTests.snapshotterOptions(size: mapView.bounds.size) let options = MLNMapSnapshotterSwiftTests.snapshotterOptions(size: mapView.bounds.size)
@@ -36,10 +35,9 @@ class MLNMapSnapshotterSwiftTests: MLNMapViewIntegrationTest {
dg.enter() dg.enter()
DispatchQueue.main.async { DispatchQueue.main.async {
let snapshotter = MLNMapSnapshotter(options: options) let snapshotter = MLNMapSnapshotter(options: options)
snapshotter.start(completionHandler: { (snapshot, error) in snapshotter.start(completionHandler: { snapshot, error in
// // Without capturing snapshotter: // // Without capturing snapshotter:
// XCTAssertNil(snapshot) // XCTAssertNil(snapshot)
@@ -61,20 +59,20 @@ class MLNMapSnapshotterSwiftTests: MLNMapViewIntegrationTest {
wait(for: [expectation], timeout: timeout) wait(for: [expectation], timeout: timeout)
} }
func testSnapshotOverlaySwiftErgonomicsLOCKED() { func testSnapshotOverlaySwiftErgonomicsLOCKED() {
let options = MLNMapSnapshotterSwiftTests.snapshotterOptions(size: mapView.bounds.size) let options = MLNMapSnapshotterSwiftTests.snapshotterOptions(size: mapView.bounds.size)
let snapshotter = MLNMapSnapshotter(options: options) let snapshotter = MLNMapSnapshotter(options: options)
let expectation = self.expectation(description: "snapshot") let expectation = expectation(description: "snapshot")
expectation.expectedFulfillmentCount = 2 expectation.expectedFulfillmentCount = 2
snapshotter.start(overlayHandler: { (overlay) in snapshotter.start(overlayHandler: { overlay in
guard let _ = overlay.context.makeImage() else { guard let _ = overlay.context.makeImage() else {
XCTFail() XCTFail()
return return
} }
expectation.fulfill() expectation.fulfill()
}) { (_, _) in }) { _, _ in
expectation.fulfill() expectation.fulfill()
} }
wait(for: [expectation], timeout: 10) wait(for: [expectation], timeout: 10)

View File

@@ -8,7 +8,6 @@
import XCTest import XCTest
class bench_UITests: XCTestCase { class bench_UITests: XCTestCase {
override func setUpWithError() throws { override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class. // Put setup code here. This method is called before the invocation of each test method in the class.

View File

@@ -8,20 +8,19 @@
import XCTest import XCTest
extension XCTestCase { extension XCTestCase {
/// `screenshot` — Save a PNG screenshot to the UITest results /// `screenshot` — Save a PNG screenshot to the UITest results
/// - Parameter name: friendly name to include. /// - Parameter name: friendly name to include.
/// Associate an image with the Activity - See [add()](https://developer.apple.com/documentation/xctest/xctactivity/2887222-add) /// Associate an image with the Activity - See [add()](https://developer.apple.com/documentation/xctest/xctactivity/2887222-add)
/// - returns: XCTAttachment, which will need to be `add`ed to the `XCTActivity` /// - returns: XCTAttachment, which will need to be `add`ed to the `XCTActivity`
/** /**
``` ```
/// rely on the calling test functions name /// rely on the calling test functions name
add(screenshot()) add(screenshot())
/// Add by name /// Add by name
add(screenshot(name: "Example")) add(screenshot(name: "Example"))
``` ```
*/ */
func screenshot(name: String = #function) -> XCTAttachment { func screenshot(name: String = #function) -> XCTAttachment {
let attachmentName = "MapLibre-Screenshot-\(name)-\(UIDevice.current.name)-\(UIDevice.current.systemVersion).png" let attachmentName = "MapLibre-Screenshot-\(name)-\(UIDevice.current.name)-\(UIDevice.current.systemVersion).png"
let screenshot = XCUIScreen.main.screenshot() let screenshot = XCUIScreen.main.screenshot()

View File

@@ -8,7 +8,6 @@
import XCTest import XCTest
class iosapp_UITests: XCTestCase { class iosapp_UITests: XCTestCase {
let app = XCUIApplication() let app = XCUIApplication()
override func setUpWithError() throws { override func setUpWithError() throws {
@@ -31,42 +30,42 @@ class iosapp_UITests: XCTestCase {
func test_iosappScheme() throws { func test_iosappScheme() throws {
/// Launch and take a screenshot /// Launch and take a screenshot
app.navigationBars["MapLibre Basic"].buttons["Map settings"].tap() app.navigationBars["MapLibre Basic"].buttons["Map settings"].tap()
app.tables/*@START_MENU_TOKEN@*/.staticTexts["Reset position"]/*[[".cells.staticTexts[\"Reset position\"]",".staticTexts[\"Reset position\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap() app.tables/*@START_MENU_TOKEN@*/ .staticTexts["Reset position"]/*[[".cells.staticTexts[\"Reset position\"]",".staticTexts[\"Reset position\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/ .tap()
sleep(1) sleep(1)
add(screenshot()) add(screenshot())
} }
/// Turn on Debug tile boundaries, tile info and FPS ornaments /// Turn on Debug tile boundaries, tile info and FPS ornaments
/// Demonstrates how the Tile Boundaries look when rendered /// Demonstrates how the Tile Boundaries look when rendered
func testDebugBoundaryTiles() { func testDebugBoundaryTiles() {
app.windows.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.doubleTap() app.windows.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.doubleTap()
let mapSettingsButton = app.navigationBars["MapLibre Basic"].buttons["Map settings"] let mapSettingsButton = app.navigationBars["MapLibre Basic"].buttons["Map settings"]
mapSettingsButton.tap() mapSettingsButton.tap()
/// setup initial conditions for position (0,0) and debug settings /// setup initial conditions for position (0,0) and debug settings
let tablesQuery = app.tables let tablesQuery = app.tables
tablesQuery/*@START_MENU_TOKEN@*/.staticTexts["Show zoom level ornament"]/*[[".cells.staticTexts[\"Show zoom level ornament\"]",".staticTexts[\"Show zoom level ornament\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap() tablesQuery/*@START_MENU_TOKEN@*/ .staticTexts["Show zoom level ornament"]/*[[".cells.staticTexts[\"Show zoom level ornament\"]",".staticTexts[\"Show zoom level ornament\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/ .tap()
mapSettingsButton.tap() mapSettingsButton.tap()
tablesQuery/*@START_MENU_TOKEN@*/.staticTexts["Show tile boundaries"]/*[[".cells.staticTexts[\"Show tile boundaries\"]",".staticTexts[\"Show tile boundaries\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap() tablesQuery/*@START_MENU_TOKEN@*/ .staticTexts["Show tile boundaries"]/*[[".cells.staticTexts[\"Show tile boundaries\"]",".staticTexts[\"Show tile boundaries\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/ .tap()
mapSettingsButton.tap() mapSettingsButton.tap()
tablesQuery/*@START_MENU_TOKEN@*/.staticTexts["Show tile info"]/*[[".cells.staticTexts[\"Show tile info\"]",".staticTexts[\"Show tile info\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap() tablesQuery/*@START_MENU_TOKEN@*/ .staticTexts["Show tile info"]/*[[".cells.staticTexts[\"Show tile info\"]",".staticTexts[\"Show tile info\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/ .tap()
mapSettingsButton.tap() mapSettingsButton.tap()
tablesQuery/*@START_MENU_TOKEN@*/.staticTexts["Show tile timestamps"]/*[[".cells.staticTexts[\"Show tile timestamps\"]",".staticTexts[\"Show tile timestamps\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap() tablesQuery/*@START_MENU_TOKEN@*/ .staticTexts["Show tile timestamps"]/*[[".cells.staticTexts[\"Show tile timestamps\"]",".staticTexts[\"Show tile timestamps\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/ .tap()
mapSettingsButton.tap() mapSettingsButton.tap()
tablesQuery.staticTexts["Add Test Shapes"].tap() tablesQuery.staticTexts["Add Test Shapes"].tap()
sleep(1) sleep(1)
add(screenshot(name: "Add Test Shapes")) add(screenshot(name: "Add Test Shapes"))
mapSettingsButton.tap() mapSettingsButton.tap()
tablesQuery.staticTexts["Reset position"].tap() tablesQuery.staticTexts["Reset position"].tap()
sleep(1) sleep(1)
add(screenshot(name: "Null Island, Zoom=0")) add(screenshot(name: "Null Island, Zoom=0"))
} }
var mapSettingsButton: XCUIElement { get { app.navigationBars["MapLibre Basic"].buttons["Map settings"] } } var mapSettingsButton: XCUIElement { app.navigationBars["MapLibre Basic"].buttons["Map settings"] }
/// Open and close the secondary map view a few times to ensure that the dynamic layout adjustment doesn't crash /// Open and close the secondary map view a few times to ensure that the dynamic layout adjustment doesn't crash
func testSecondMap() { func testSecondMap() {
@@ -77,7 +76,7 @@ class iosapp_UITests: XCTestCase {
let secondMapQuery = app.otherElements["Second Map"] let secondMapQuery = app.otherElements["Second Map"]
XCTAssert(!secondMapQuery.exists) XCTAssert(!secondMapQuery.exists)
for _ in 0..<iterations { for _ in 0 ..< iterations {
mapSettingsButton.tap() mapSettingsButton.tap()
app.tables.staticTexts["Show Second Map"].tap() app.tables.staticTexts["Show Second Map"].tap()
XCTAssert(secondMapQuery.waitForExistence(timeout: showTimeout)) XCTAssert(secondMapQuery.waitForExistence(timeout: showTimeout))
@@ -94,76 +93,76 @@ class iosapp_UITests: XCTestCase {
func testAll() { func testAll() {
let allItems = [ let allItems = [
"Reset position", "Reset position",
"Show tile boundaries", "Show tile boundaries",
"Hide tile boundaries", "Hide tile boundaries",
"Show tile info", "Show tile info",
"Hide tile info", "Hide tile info",
"Show tile timestamps", "Show tile timestamps",
"Hide tile timestamps", "Hide tile timestamps",
"Show collision boxes", "Show collision boxes",
"Hide collision boxes", "Hide collision boxes",
"Show overdraw visualization", "Show overdraw visualization",
"Hide overdraw visualization", "Hide overdraw visualization",
"Show zoom level ornament", "Show zoom level ornament",
"Hide zoom level ornament", "Hide zoom level ornament",
"Show frame time graph", "Show frame time graph",
"Hide frame time graph", "Hide frame time graph",
"Show reuse queue stats", "Show reuse queue stats",
"Hide reuse queue stats", "Hide reuse queue stats",
"Add 100 Views", "Add 100 Views",
//"Add 1,000 Views", // These cause the test to time out // "Add 1,000 Views", // These cause the test to time out
//"Add 10,000 Views", // "Add 10,000 Views",
"Add 100 Sprites", "Add 100 Sprites",
//"Add 1,000 Sprites", // "Add 1,000 Sprites",
//"Add 10,000 Sprites", // "Add 10,000 Sprites",
"Animate an Annotation View", "Animate an Annotation View",
"Add Test Shapes", "Add Test Shapes",
"Add 10x Test Shapes", "Add 10x Test Shapes",
"Add Point With Custom Callout", "Add Point With Custom Callout",
"Query Annotations", "Query Annotations",
"Enable Custom User Dot", "Enable Custom User Dot",
"Disable Custom User Dot", "Disable Custom User Dot",
"Remove Annotations", "Remove Annotations",
"Select an offscreen point annotation", "Select an offscreen point annotation",
"Center selected annotation", "Center selected annotation",
"Add visible area polyline", "Add visible area polyline",
"Add Building Extrusions", "Add Building Extrusions",
"Style Water With Function", "Style Water With Function",
"Style Roads With Function", "Style Roads With Function",
"Add Raster & Apply Function", "Add Raster & Apply Function",
"Add Shapes & Apply Fill", "Add Shapes & Apply Fill",
"Style Symbol Color", "Style Symbol Color",
"Style Building Fill Color", "Style Building Fill Color",
"Style Ferry Line Color", "Style Ferry Line Color",
"Remove Parks", "Remove Parks",
"Style Fill With Filter", "Style Fill With Filter",
"Style Lines With Filter", "Style Lines With Filter",
"Style Fill With Numeric Filter", "Style Fill With Numeric Filter",
"Query and Style Features", "Query and Style Features",
"Style Feature", "Style Feature",
"Style Dynamic Point Collection", "Style Dynamic Point Collection",
"Update Shape Source: Data", "Update Shape Source: Data",
"Update Shape Source: URL", "Update Shape Source: URL",
"Update Shape Source: Features", "Update Shape Source: Features",
"Style Vector Tile Source", "Style Vector Tile Source",
"Style Raster Tile Source", "Style Raster Tile Source",
"Style Image Source", "Style Image Source",
"Add Route Line", "Add Route Line",
"Dynamically Style Polygon", "Dynamically Style Polygon",
"Add Custom Lat/Lon Grid", "Add Custom Lat/Lon Grid",
"Style Route line with gradient", "Style Route line with gradient",
"Start World Tour", "Start World Tour",
"Random Tour", "Random Tour",
"Show Second Map", "Show Second Map",
"Hide Second Map", "Hide Second Map",
"Missing Icon", "Missing Icon",
"Limit Camera Changes", "Limit Camera Changes",
"Unlimit Camera Changes", "Unlimit Camera Changes",
"Turn On Content Insets", "Turn On Content Insets",
"Turn Off Content Insets", "Turn Off Content Insets",
"Lat Long bounds with padding", "Lat Long bounds with padding",
"Show Labels in Default Language", "Show Labels in Default Language",
] ]
for label in allItems { for label in allItems {
@@ -175,7 +174,8 @@ class iosapp_UITests: XCTestCase {
// Only one of these will show up, run whichever one is there // Only one of these will show up, run whichever one is there
mapSettingsButton.tap() mapSettingsButton.tap()
if let customLayer = staticItemIfExists("Add Custom Triangle Layer (OpenGL)") ?? if let customLayer = staticItemIfExists("Add Custom Triangle Layer (OpenGL)") ??
staticItemIfExists("Add Custom Triangle Layer (Metal)") { staticItemIfExists("Add Custom Triangle Layer (Metal)")
{
customLayer.tap() customLayer.tap()
sleep(1) sleep(1)
mapSettingsButton.tap() mapSettingsButton.tap()
@@ -188,7 +188,7 @@ class iosapp_UITests: XCTestCase {
} }
// See `bestLanguageForUser` // See `bestLanguageForUser`
for loc in [ "ar", "de", "en", "es", "fr", "ja", "ko", "pt", "ru", "zh", "zh-Hans", "zh-Hant" ] { for loc in ["ar", "de", "en", "es", "fr", "ja", "ko", "pt", "ru", "zh", "zh-Hans", "zh-Hant"] {
if let name = NSLocale(localeIdentifier: loc).displayName(forKey: .identifier, value: loc) { if let name = NSLocale(localeIdentifier: loc).displayName(forKey: .identifier, value: loc) {
if let item = staticItemIfExists("Show Labels in " + name) { if let item = staticItemIfExists("Show Labels in " + name) {
item.tap() item.tap()
@@ -223,9 +223,9 @@ class iosapp_UITests: XCTestCase {
private func tapBackButton(_ label: String, timeout: TimeInterval) -> Bool { private func tapBackButton(_ label: String, timeout: TimeInterval) -> Bool {
let bar = app.navigationBars[label] let bar = app.navigationBars[label]
if (bar.waitForExistence(timeout: timeout)) { if bar.waitForExistence(timeout: timeout) {
let button = bar.buttons["Back"] let button = bar.buttons["Back"]
if (button.waitForExistence(timeout: 1)) { if button.waitForExistence(timeout: 1) {
button.tap() button.tap()
return true return true
} }
@@ -247,14 +247,14 @@ class iosapp_UITests: XCTestCase {
} }
} }
} }
/// Make sure the Custom Drawable Layer does not crash /// Make sure the Custom Drawable Layer does not crash
func testCustomDrawableLayer() { func testCustomDrawableLayer() {
app.windows.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.doubleTap() app.windows.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.doubleTap()
let mapSettingsButton = app.navigationBars["MapLibre Basic"].buttons["Map settings"] let mapSettingsButton = app.navigationBars["MapLibre Basic"].buttons["Map settings"]
mapSettingsButton.tap() mapSettingsButton.tap()
let tablesQuery = app.tables let tablesQuery = app.tables
tablesQuery.staticTexts["Add Custom Drawable Layer"].tap() tablesQuery.staticTexts["Add Custom Drawable Layer"].tap()
sleep(5) sleep(5)

View File

@@ -6,14 +6,16 @@ let package = Package(
products: [ products: [
.library( .library(
name: "Mapbox", name: "Mapbox",
targets: ["Mapbox"]) targets: ["Mapbox"]
),
], ],
dependencies: [ dependencies: [
], ],
targets: [ targets: [
.binaryTarget( .binaryTarget(
name: "Mapbox", name: "Mapbox",
url: "MAPLIBRE_PACKAGE_URL", url: "MAPLIBRE_PACKAGE_URL",
checksum: "MAPLIBRE_PACKAGE_CHECKSUM") checksum: "MAPLIBRE_PACKAGE_CHECKSUM"
),
] ]
) )

View File

@@ -1,23 +1,19 @@
import XCTest
import MapLibre import MapLibre
import XCTest
class CustomAnnotationView: MLNAnnotationView { class CustomAnnotationView: MLNAnnotationView {
override init(reuseIdentifier: String?) { override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier) super.init(reuseIdentifier: reuseIdentifier)
} }
required init?(coder aDecoder: NSCoder) { required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
} }
} }
class MLNAnnotationViewIntegrationTests: XCTestCase { class MLNAnnotationViewIntegrationTests: XCTestCase {
func testCreatingCustomAnnotationView() { func testCreatingCustomAnnotationView() {
let customAnnotationView = CustomAnnotationView(reuseIdentifier: "resuse-id") let customAnnotationView = CustomAnnotationView(reuseIdentifier: "resuse-id")
XCTAssertNotNil(customAnnotationView) XCTAssertNotNil(customAnnotationView)
} }
} }

View File

@@ -1,109 +1,106 @@
import XCTest
import MapLibre import MapLibre
import XCTest
class MLNMapViewDelegateIntegrationTests: XCTestCase { class MLNMapViewDelegateIntegrationTests: XCTestCase {
func testCoverage() { func testCoverage() {
MLNSDKTestHelpers.checkTestsContainAllMethods(testClass: MLNMapViewDelegateIntegrationTests.self, in: MLNMapViewDelegate.self) MLNSDKTestHelpers.checkTestsContainAllMethods(testClass: MLNMapViewDelegateIntegrationTests.self, in: MLNMapViewDelegate.self)
} }
} }
extension MLNMapViewDelegateIntegrationTests: MLNMapViewDelegate { extension MLNMapViewDelegateIntegrationTests: MLNMapViewDelegate {
func mapViewRegionIsChanging(_: MLNMapView) {}
func mapViewRegionIsChanging(_ mapView: MLNMapView) {} func mapViewRegionIsChanging(_: MLNMapView, reason _: MLNCameraChangeReason) {}
func mapViewRegionIsChanging(_ mapView: MLNMapView, reason: MLNCameraChangeReason) {} func mapView(_: MLNMapView, regionIsChangingWith _: MLNCameraChangeReason) {}
func mapView(_ mapView: MLNMapView, regionIsChangingWith reason: MLNCameraChangeReason) {} func mapView(_: MLNMapView, didChange _: MLNUserTrackingMode, animated _: Bool) {}
func mapView(_ mapView: MLNMapView, didChange mode: MLNUserTrackingMode, animated: Bool) {} func mapViewDidFinishLoadingMap(_: MLNMapView) {}
func mapViewDidFinishLoadingMap(_ mapView: MLNMapView) {} func mapViewDidStopLocatingUser(_: MLNMapView) {}
func mapViewDidStopLocatingUser(_ mapView: MLNMapView) {} func mapViewWillStartLoadingMap(_: MLNMapView) {}
func mapViewWillStartLoadingMap(_ mapView: MLNMapView) {} func mapViewWillStartLocatingUser(_: MLNMapView) {}
func mapViewWillStartLocatingUser(_ mapView: MLNMapView) {} func mapViewWillStartRenderingMap(_: MLNMapView) {}
func mapViewWillStartRenderingMap(_ mapView: MLNMapView) {} func mapViewWillStartRenderingFrame(_: MLNMapView) {}
func mapViewWillStartRenderingFrame(_ mapView: MLNMapView) {} func mapView(_: MLNMapView, didFinishLoading _: MLNStyle) {}
func mapView(_ mapView: MLNMapView, didFinishLoading style: MLNStyle) {} func mapView(_: MLNMapView, didSelect _: MLNAnnotation) {}
func mapView(_ mapView: MLNMapView, didSelect annotation: MLNAnnotation) {} func mapView(_: MLNMapView, didDeselect _: MLNAnnotation) {}
func mapView(_ mapView: MLNMapView, didDeselect annotation: MLNAnnotation) {} func mapView(_: MLNMapView, didSingleTapAt _: CLLocationCoordinate2D) {}
func mapView(_ mapView: MLNMapView, didSingleTapAt coordinate: CLLocationCoordinate2D) {} func mapView(_: MLNMapView, regionDidChangeAnimated _: Bool) {}
func mapView(_ mapView: MLNMapView, regionDidChangeAnimated animated: Bool) {} func mapView(_: MLNMapView, regionDidChangeWith _: MLNCameraChangeReason, animated _: Bool) {}
func mapView(_ mapView: MLNMapView, regionDidChangeWith reason: MLNCameraChangeReason, animated: Bool) {} func mapView(_: MLNMapView, regionWillChangeAnimated _: Bool) {}
func mapView(_ mapView: MLNMapView, regionWillChangeAnimated animated: Bool) {} func mapView(_: MLNMapView, regionWillChangeWith _: MLNCameraChangeReason, animated _: Bool) {}
func mapView(_ mapView: MLNMapView, regionWillChangeWith reason: MLNCameraChangeReason, animated: Bool) {} func mapViewDidFailLoadingMap(_: MLNMapView, withError _: Error) {}
func mapViewDidFailLoadingMap(_ mapView: MLNMapView, withError error: Error) {} func mapView(_: MLNMapView, didUpdate _: MLNUserLocation?) {}
func mapView(_ mapView: MLNMapView, didUpdate userLocation: MLNUserLocation?) {} func mapViewDidFinishRenderingMap(_: MLNMapView, fullyRendered _: Bool) {}
func mapViewDidFinishRenderingMap(_ mapView: MLNMapView, fullyRendered: Bool) {} func mapViewDidBecomeIdle(_: MLNMapView) {}
func mapViewDidBecomeIdle(_ mapView: MLNMapView) {}
func mapView(_ mapView: MLNMapView, didFailToLocateUserWithError error: Error) {} func mapView(_: MLNMapView, didFailToLocateUserWithError _: Error) {}
func mapView(_ mapView: MLNMapView, tapOnCalloutFor annotation: MLNAnnotation) {} func mapView(_: MLNMapView, tapOnCalloutFor _: MLNAnnotation) {}
func mapViewDidFinishRenderingFrame(_ mapView: MLNMapView, fullyRendered: Bool) {} func mapViewDidFinishRenderingFrame(_: MLNMapView, fullyRendered _: Bool) {}
func mapViewDidFinishRenderingFrame(_ mapView: MLNMapView, fullyRendered: Bool, frameEncodingTime: Double, frameRenderingTime: Double) {} func mapViewDidFinishRenderingFrame(_: MLNMapView, fullyRendered _: Bool, frameEncodingTime _: Double, frameRenderingTime _: Double) {}
func mapView(_ mapView: MLNMapView, shapeAnnotationIsEnabled annotation: MLNShape) -> Bool { return false }
func mapView(_ mapView: MLNMapView, didAdd annotationViews: [MLNAnnotationView]) {} func mapView(_: MLNMapView, shapeAnnotationIsEnabled _: MLNShape) -> Bool { false }
func mapView(_ mapView: MLNMapView, didSelect annotationView: MLNAnnotationView) {} func mapView(_: MLNMapView, didAdd _: [MLNAnnotationView]) {}
func mapView(_ mapView: MLNMapView, didDeselect annotationView: MLNAnnotationView) {} func mapView(_: MLNMapView, didSelect _: MLNAnnotationView) {}
func mapView(_ mapView: MLNMapView, alphaForShapeAnnotation annotation: MLNShape) -> CGFloat { return 0 } func mapView(_: MLNMapView, didDeselect _: MLNAnnotationView) {}
func mapView(_ mapView: MLNMapView, viewFor annotation: MLNAnnotation) -> MLNAnnotationView? { return nil } func mapView(_: MLNMapView, alphaForShapeAnnotation _: MLNShape) -> CGFloat { 0 }
func mapView(_ mapView: MLNMapView, imageFor annotation: MLNAnnotation) -> MLNAnnotationImage? { return nil } func mapView(_: MLNMapView, viewFor _: MLNAnnotation) -> MLNAnnotationView? { nil }
func mapView(_ mapView: MLNMapView, annotationCanShowCallout annotation: MLNAnnotation) -> Bool { return false } func mapView(_: MLNMapView, imageFor _: MLNAnnotation) -> MLNAnnotationImage? { nil }
func mapView(_ mapView: MLNMapView, calloutViewFor annotation: MLNAnnotation) -> MLNCalloutView? { return nil } func mapView(_: MLNMapView, annotationCanShowCallout _: MLNAnnotation) -> Bool { false }
func mapView(_ mapView: MLNMapView, strokeColorForShapeAnnotation annotation: MLNShape) -> UIColor { return .black } func mapView(_: MLNMapView, calloutViewFor _: MLNAnnotation) -> MLNCalloutView? { nil }
func mapView(_ mapView: MLNMapView, fillColorForPolygonAnnotation annotation: MLNPolygon) -> UIColor { return .black } func mapView(_: MLNMapView, strokeColorForShapeAnnotation _: MLNShape) -> UIColor { .black }
func mapView(_ mapView: MLNMapView, leftCalloutAccessoryViewFor annotation: MLNAnnotation) -> UIView? { return nil } func mapView(_: MLNMapView, fillColorForPolygonAnnotation _: MLNPolygon) -> UIColor { .black }
func mapView(_ mapView: MLNMapView, lineWidthForPolylineAnnotation annotation: MLNPolyline) -> CGFloat { return 0 } func mapView(_: MLNMapView, leftCalloutAccessoryViewFor _: MLNAnnotation) -> UIView? { nil }
func mapView(_ mapView: MLNMapView, rightCalloutAccessoryViewFor annotation: MLNAnnotation) -> UIView? { return nil } func mapView(_: MLNMapView, lineWidthForPolylineAnnotation _: MLNPolyline) -> CGFloat { 0 }
func mapView(_ mapView: MLNMapView, annotation: MLNAnnotation, calloutAccessoryControlTapped control: UIControl) {} func mapView(_: MLNMapView, rightCalloutAccessoryViewFor _: MLNAnnotation) -> UIView? { nil }
func mapView(_ mapView: MLNMapView, shouldChangeFrom oldCamera: MLNMapCamera, to newCamera: MLNMapCamera) -> Bool { return false } func mapView(_: MLNMapView, annotation _: MLNAnnotation, calloutAccessoryControlTapped _: UIControl) {}
func mapView(_ mapView: MLNMapView, shouldChangeFrom oldCamera: MLNMapCamera, to newCamera: MLNMapCamera, reason: MLNCameraChangeReason) -> Bool { return false } func mapView(_: MLNMapView, shouldChangeFrom _: MLNMapCamera, to _: MLNMapCamera) -> Bool { false }
func mapViewUserLocationAnchorPoint(_ mapView: MLNMapView) -> CGPoint { return CGPoint(x: 100, y: 100) }
func mapView(_ mapView: MLNMapView, didFailToLoadImage imageName: String) -> UIImage? { return nil }
func mapView(_ mapView: MLNMapView, shouldRemoveStyleImage imageName: String) -> Bool { return false }
func mapView(_ mapView: MLNMapView, didChangeLocationManagerAuthorization manager: MLNLocationManager) {} func mapView(_: MLNMapView, shouldChangeFrom _: MLNMapCamera, to _: MLNMapCamera, reason _: MLNCameraChangeReason) -> Bool { false }
func mapView(styleForDefaultUserLocationAnnotationView mapView: MLNMapView) -> MLNUserLocationAnnotationViewStyle { return MLNUserLocationAnnotationViewStyle() } func mapViewUserLocationAnchorPoint(_: MLNMapView) -> CGPoint { CGPoint(x: 100, y: 100) }
func mapView(_: MLNMapView, didFailToLoadImage _: String) -> UIImage? { nil }
func mapView(_: MLNMapView, shouldRemoveStyleImage _: String) -> Bool { false }
func mapView(_: MLNMapView, didChangeLocationManagerAuthorization _: MLNLocationManager) {}
func mapView(styleForDefaultUserLocationAnnotationView _: MLNMapView) -> MLNUserLocationAnnotationViewStyle { MLNUserLocationAnnotationViewStyle() }
} }

View File

@@ -1,65 +1,62 @@
import XCTest
import Mapbox import Mapbox
import XCTest
class MLNMapViewDelegateIntegrationTests: XCTestCase { class MLNMapViewDelegateIntegrationTests: XCTestCase {
func testCoverage() { func testCoverage() {
MLNSDKTestHelpers.checkTestsContainAllMethods(testClass: MLNMapViewDelegateIntegrationTests.self, in: MLNMapViewDelegate.self) MLNSDKTestHelpers.checkTestsContainAllMethods(testClass: MLNMapViewDelegateIntegrationTests.self, in: MLNMapViewDelegate.self)
} }
} }
extension MLNMapViewDelegateIntegrationTests: MLNMapViewDelegate { extension MLNMapViewDelegateIntegrationTests: MLNMapViewDelegate {
func mapView(_: MLNMapView, shouldChangeFrom _: MLNMapCamera, to _: MLNMapCamera) -> Bool { false }
func mapView(_ mapView: MLNMapView, shouldChangeFrom oldCamera: MLNMapCamera, to newCamera: MLNMapCamera) -> Bool { return false } func mapView(_: MLNMapView, lineWidthForPolylineAnnotation _: MLNPolyline) -> CGFloat { 0 }
func mapView(_ mapView: MLNMapView, lineWidthForPolylineAnnotation annotation: MLNPolyline) -> CGFloat { return 0 } func mapView(_: MLNMapView, annotationCanShowCallout _: MLNAnnotation) -> Bool { false }
func mapView(_ mapView: MLNMapView, annotationCanShowCallout annotation: MLNAnnotation) -> Bool { return false } func mapView(_: MLNMapView, imageFor _: MLNAnnotation) -> MLNAnnotationImage? { nil }
func mapView(_ mapView: MLNMapView, imageFor annotation: MLNAnnotation) -> MLNAnnotationImage? { return nil } func mapView(_: MLNMapView, alphaForShapeAnnotation _: MLNShape) -> CGFloat { 0 }
func mapView(_ mapView: MLNMapView, alphaForShapeAnnotation annotation: MLNShape) -> CGFloat { return 0 } func mapViewDidFinishRenderingFrame(_: MLNMapView, fullyRendered _: Bool) {}
func mapViewDidFinishRenderingFrame(_ mapView: MLNMapView, fullyRendered: Bool) {} func mapViewDidFinishRenderingFrame(_: MLNMapView, fullyRendered _: Bool, frameTime _: Double) {}
func mapViewDidFinishRenderingFrame(_ mapView: MLNMapView, fullyRendered: Bool, frameTime: Double) {} func mapViewDidFinishRenderingMap(_: MLNMapView, fullyRendered _: Bool) {}
func mapViewDidFinishRenderingMap(_ mapView: MLNMapView, fullyRendered: Bool) {} func mapViewDidBecomeIdle(_: MLNMapView) {}
func mapViewDidBecomeIdle(_ mapView: MLNMapView) {}
func mapViewDidFailLoadingMap(_ mapView: MLNMapView, withError error: Error) {} func mapViewDidFailLoadingMap(_: MLNMapView, withError _: Error) {}
func mapView(_ mapView: MLNMapView, didFailToLoadImage imageName: String) -> NSImage? { return nil } func mapView(_: MLNMapView, didFailToLoadImage _: String) -> NSImage? { nil }
func mapView(_ mapView: MLNMapView, shapeAnnotationIsEnabled annotation: MLNShape) -> Bool { return false }
func mapView(_ mapView: MLNMapView, didDeselect annotation: MLNAnnotation) {} func mapView(_: MLNMapView, shapeAnnotationIsEnabled _: MLNShape) -> Bool { false }
func mapView(_ mapView: MLNMapView, didSelect annotation: MLNAnnotation) {} func mapView(_: MLNMapView, didDeselect _: MLNAnnotation) {}
func mapView(_ mapView: MLNMapView, didFinishLoading style: MLNStyle) {} func mapView(_: MLNMapView, didSelect _: MLNAnnotation) {}
func mapViewWillStartRenderingFrame(_ mapView: MLNMapView) {} func mapView(_: MLNMapView, didFinishLoading _: MLNStyle) {}
func mapViewWillStartRenderingMap(_ mapView: MLNMapView) {} func mapViewWillStartRenderingFrame(_: MLNMapView) {}
func mapViewWillStartLoadingMap(_ mapView: MLNMapView) {} func mapViewWillStartRenderingMap(_: MLNMapView) {}
func mapViewDidFinishLoadingMap(_ mapView: MLNMapView) {} func mapViewWillStartLoadingMap(_: MLNMapView) {}
func mapViewCameraIsChanging(_ mapView: MLNMapView) {} func mapViewDidFinishLoadingMap(_: MLNMapView) {}
func mapView(_ mapView: MLNMapView, cameraDidChangeAnimated animated: Bool) {} func mapViewCameraIsChanging(_: MLNMapView) {}
func mapView(_ mapView: MLNMapView, cameraWillChangeAnimated animated: Bool) {} func mapView(_: MLNMapView, cameraDidChangeAnimated _: Bool) {}
func mapView(_ mapView: MLNMapView, strokeColorForShapeAnnotation annotation: MLNShape) -> NSColor { return .black } func mapView(_: MLNMapView, cameraWillChangeAnimated _: Bool) {}
func mapView(_ mapView: MLNMapView, fillColorForPolygonAnnotation annotation: MLNPolygon) -> NSColor { return .black } func mapView(_: MLNMapView, strokeColorForShapeAnnotation _: MLNShape) -> NSColor { .black }
func mapView(_ mapView: MLNMapView, calloutViewControllerFor annotation: MLNAnnotation) -> NSViewController? { return nil } func mapView(_: MLNMapView, fillColorForPolygonAnnotation _: MLNPolygon) -> NSColor { .black }
func mapView(_ mapView: MLNMapView, shouldRemoveStyleImage imageName: String) -> Bool { return false } func mapView(_: MLNMapView, calloutViewControllerFor _: MLNAnnotation) -> NSViewController? { nil }
func mapView(_: MLNMapView, shouldRemoveStyleImage _: String) -> Bool { false }
} }

View File

@@ -1,8 +1,9 @@
#!/usr/bin/swift #!/usr/bin/swift
import Foundation
/// Generates Entitlement files .xcent for codesigning, containing the correct team id /// Generates Entitlement files .xcent for codesigning, containing the correct team id
import Swift import Swift
import Foundation
let fileManager = FileManager.default let fileManager = FileManager.default
@@ -16,12 +17,11 @@ guard let rawTeamIdEnv = getenv("IOS_DEVELOPMENT_TEAM") else {
let teamId2 = String(utf8String: rawTeamIdEnv) let teamId2 = String(utf8String: rawTeamIdEnv)
for file in contentsOfCurrentWorkingDirectory { for file in contentsOfCurrentWorkingDirectory {
if (file.pathExtension == "template") { if file.pathExtension == "template" {
var content = "" var content = ""
do { do {
content = try String(contentsOf: file, encoding: .utf8) content = try String(contentsOf: file, encoding: .utf8)
} } catch {
catch {
print("Error reading xcent file: \(error).") print("Error reading xcent file: \(error).")
} }
@@ -32,9 +32,8 @@ for file in contentsOfCurrentWorkingDirectory {
do { do {
try content.write(to: targetFile, atomically: false, encoding: .utf8) try content.write(to: targetFile, atomically: false, encoding: .utf8)
print("Entitlement " + targetFile.absoluteString + " generated.") print("Entitlement " + targetFile.absoluteString + " generated.")
} } catch {
catch {
print("Error writing xcent file: \(error).") print("Error writing xcent file: \(error).")
} }
} }
} }