Skip to content
This repository has been archived by the owner on Jul 19, 2023. It is now read-only.

Commit

Permalink
Rebranded package
Browse files Browse the repository at this point in the history
  • Loading branch information
devmaximilian committed Feb 7, 2021
1 parent 6215c6f commit e4499cc
Show file tree
Hide file tree
Showing 14 changed files with 211 additions and 239 deletions.
12 changes: 6 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import PackageDescription

let package = Package(
name: "Forecast",
name: "Weather",
platforms: [
.macOS(.v10_15),
.iOS(.v13),
Expand All @@ -14,8 +14,8 @@ let package = Package(
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "Forecast",
targets: ["Forecast"]),
name: "Weather",
targets: ["Weather"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
Expand All @@ -25,10 +25,10 @@ let package = Package(
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "Forecast",
name: "Weather",
dependencies: []),
.testTarget(
name: "ForecastTests",
dependencies: ["Forecast"]),
name: "WeatherTests",
dependencies: ["Weather"]),
]
)
21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# Forecast
# Weather

This package is a wrapper for the PMP3g API provided by [SMHI](https://smhi.se).

### Usage

Add Forecast to your `Package.swift` manifest.
Add Weather o your `Package.swift` manifest.

```swift
...
/// Append the package to the list of dependencies
dependencies: [
.package(url: "https://github.com/devmaximilian/Forecast.git", from: "1.0.0")
.package(url: "https://github.com/devmaximilian/Weather.git", from: "1.0.0")
],

/// Append the library to the list of target dependencies
targets: [
.target(
name: "MyProject",
dependencies: ["Forecast"])
dependencies: ["Weather"])
]
...
```
Expand All @@ -28,16 +28,13 @@ Note that this is just a simple example demonstrating how the library can be use
var cancellables: [String: AnyCancellable] = [:]

/// Request the current weather forecast for Stockholm
let forecastPublisher = ForecastPublisher(latitude: 59.3258414, longitude: 17.7018733)
let weatherPublisher = Weather.publisher(latitude: 59.3258414, longitude: 17.7018733)

cancellables["forecast-request"] = forecastPublisher
cancellables["weather"] = weatherPublisher
.assertNoFailure()
.sink { observation in
/// Use the current forecast
guard let forecast = observation.timeSeries.current else { return }

/// Get the air temperature
let temperature = forecast[.airTemperature]
.sink { weather in
/// Get the current air temperature
let temperature = observation.get(\.value, for: .t)

/// Use the air temperature in some way
print("It is currently \(temperature)°C")
Expand Down
187 changes: 0 additions & 187 deletions Sources/Forecast/ForecastPublisher.swift

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Value.swift
// Parameter.swift
//
// Copyright (c) 2019 Maximilian Wendel
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
// SOFTWARE.
//

import struct Foundation.Date
import Foundation


/// An `Observation` is a collection of `Forecast` instances
public struct Observation: Decodable {
public struct Weather: Decodable {
/// A timestamp for when the `Forecast` was approved
private let approvedTime: Date

Expand All @@ -41,7 +41,7 @@ public struct Observation: Decodable {
}

/// An extension to house convenience attributes
extension Observation {
extension Weather {
/// - Returns: Whether or not the forecast is valid for the current date
public var isRelevant: Bool {
let now = Date()
Expand Down Expand Up @@ -91,7 +91,7 @@ extension Forecast {
}
}

extension Observation {
extension Weather {
fileprivate var forecast: Forecast {
return self.get() ?? Forecast(validTime: .distantPast, parameters: [])
}
Expand Down Expand Up @@ -122,3 +122,12 @@ extension Observation {
}
}
}

extension Weather {
public static func publisher(latitude: Double, longitude: Double) -> WeatherPublisher {
return WeatherPublisher(
latitude: latitude,
longitude: longitude
)
}
}
Loading

0 comments on commit e4499cc

Please sign in to comment.