From 5449a64ccc29f56618412d746f785a395d6d15a7 Mon Sep 17 00:00:00 2001 From: "RobLabs.com" Date: Mon, 11 Apr 2022 15:13:15 -0700 Subject: [PATCH 1/2] Allow API customers to set the UnitTemperature to get either US or SI (metric) results from the API --- .../services/calls/NWS+Forecast.swift | 8 +++- .../GetForecastIntegrationTests.swift | 38 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/Sources/NationalWeatherService/services/calls/NWS+Forecast.swift b/Sources/NationalWeatherService/services/calls/NWS+Forecast.swift index 72a878b..bd517df 100644 --- a/Sources/NationalWeatherService/services/calls/NWS+Forecast.swift +++ b/Sources/NationalWeatherService/services/calls/NWS+Forecast.swift @@ -10,10 +10,16 @@ import Foundation extension NationalWeatherService { public typealias ForecastHandler = (Result) -> Void + /// Allow API customers to set the [UnitTemperature](https://developer.apple.com/documentation/foundation/unittemperature) + /// to get ["*US customary or SI (metric) units in textual output*"](https://www.weather.gov/documentation/services-web-api#/default/gridpoint_forecast) + public static var units: UnitTemperature = .celsius + fileprivate func loadForecast(at url: URL, then handler: @escaping ForecastHandler) { var components = URLComponents(url: url, resolvingAgainstBaseURL: false)! + + let units: String = NationalWeatherService.units == .celsius ? "si" : "us" components.queryItems = [ - URLQueryItem(name: "units", value: "si") + URLQueryItem(name: "units", value: units) ] self.load(at: components.url!, as: Forecast.self, then: handler) diff --git a/Tests/NationalWeatherServiceTests/integration/GetForecastIntegrationTests.swift b/Tests/NationalWeatherServiceTests/integration/GetForecastIntegrationTests.swift index b82cc6b..a85910d 100644 --- a/Tests/NationalWeatherServiceTests/integration/GetForecastIntegrationTests.swift +++ b/Tests/NationalWeatherServiceTests/integration/GetForecastIntegrationTests.swift @@ -2,6 +2,7 @@ import XCTest @testable import NationalWeatherService final class GetForecastIntegrationTests: XCTestCase { + /// Get forecast without setting `NationalWeatherService.units` func testGetForecastForLocation() throws { let forecastExpectation = self.expectation(description: "get forecast expectation") nws.forecast(latitude: 47.6174, longitude: -122.2017) { result in @@ -15,7 +16,44 @@ final class GetForecastIntegrationTests: XCTestCase { wait(for: [forecastExpectation], timeout: 5) } + + /// Get forecast by setting `NationalWeatherService.units` to `.fahrenheit` + func testGetForecastFahrenheit() throws { + let forecastExpectation = self.expectation(description: "get forecast expectation") + + NationalWeatherService.units = .fahrenheit + nws.forecast(latitude: 47.6174, longitude: -122.2017) { result in + XCTAssertSuccess(result) + + let forecast = try! result.get() + print(forecast) + XCTAssertFalse(forecast.periods.isEmpty) + forecastExpectation.fulfill() + } + + wait(for: [forecastExpectation], timeout: 5) + } + + /// Get forecast by setting `NationalWeatherService.units` to `.celsius` + func testGetForecastCelsius() throws { + let forecastExpectation = self.expectation(description: "get forecast expectation") + + NationalWeatherService.units = .celsius + nws.forecast(latitude: 47.6174, longitude: -122.2017) { result in + XCTAssertSuccess(result) + + let forecast = try! result.get() + + print(forecast) + XCTAssertFalse(forecast.periods.isEmpty) + + forecastExpectation.fulfill() + } + + wait(for: [forecastExpectation], timeout: 5) + } + func testGetHourlyForecast() throws { let hourlyForecastExpectation = self.expectation(description: "get hourly forecast expectation") nws.hourlyForecast(latitude: 47.6174, longitude: -122.2017) { result in From 59ec240b474a2da1ea7459743327130b0d4e3dd3 Mon Sep 17 00:00:00 2001 From: "RobLabs.com" Date: Thu, 22 Aug 2024 07:37:27 -0700 Subject: [PATCH 2/2] Update Swift Package dependencies: GeoSwift & geos. Fixes errors when compiling with Xcode 16 --- Package.resolved | 8 ++++---- Package.swift | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Package.resolved b/Package.resolved index a78d7d7..7eccbcf 100644 --- a/Package.resolved +++ b/Package.resolved @@ -6,8 +6,8 @@ "repositoryURL": "https://github.com/GEOSwift/geos.git", "state": { "branch": null, - "revision": "083e366bc831d0f951974151315383830a79d447", - "version": "5.0.0" + "revision": "f510e634c822116fca615064d889300dba40d761", + "version": "8.1.0" } }, { @@ -15,8 +15,8 @@ "repositoryURL": "https://github.com/GEOSwift/GEOSwift.git", "state": { "branch": null, - "revision": "7e27a3b92b2ea61cf63ef1664bbe5c734cbb7447", - "version": "7.1.0" + "revision": "1fee0146ee06ca2d1e83070320b95526f3690f9d", + "version": "10.2.0" } } ] diff --git a/Package.swift b/Package.swift index fcd3bc0..7d39ae0 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.2 +// swift-tools-version:5.5 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription @@ -18,8 +18,8 @@ let package = Package( dependencies: [ // Dependencies declare other packages that this package depends on. // .package(url: /* package url */, from: "1.0.0"), - .package(url: "https://github.com/GEOSwift/GEOSwift.git", from: "7.0.0"), - .package(url: "https://github.com/GEOSwift/geos.git", from: "5.0.0") + .package(url: "https://github.com/GEOSwift/GEOSwift.git", from: "10.0.0"), + .package(url: "https://github.com/GEOSwift/geos.git", from: "8.0.0") ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite.