Statistics is a Swift package for interacting with Statistics Sweden's Open Data API.
Statistics is available through Swift Package Manager. To install it, simply include it in your package dependency list:
dependencies: [
.package(url: "https://github.com/devmaximilian/Statistics.git", from: "1.0.0"),
]
– alternatively using Xcode via File > Swift Packages > Add Package Dependency...
Fetch topics by subject area 🗃
let client = Statistics.defaultClient
// Get root navigation structure
client.navigationPublisher(for: .root)
.assertNoFailure()
.map(\.text)
.sink { links in {
print(links) // -> ["Labour market", "Population", ...]
}
Retrieve filtered statistics by a given subject 📊
// Get table (population by region, only total population)
client.tablePublisher(for: "BE0101A", subject: "BefolkningNy")
.configureRequest { builder in
builder.select("BE0101N1")
.filter("Region", by: "00")
}
.assertNoFailure()
.sink { table in {
print(table) // -> Table...
}
Only want/need data within a given interval? 📅
// Get table (population by region, only total population between 1970 – 1980)
client.tablePublisher(for: "BE0101A", subject: "BefolkningNy")
.configureRequest { builder in
builder.select("BE0101N1")
.filter("Region", by: "00")
.between("1970", "1980")
}
.assertNoFailure()
.sink { table in {
print(table) // -> Table...
}
The developer and this package are not affiliated with or endorsed by Statistics Sweden. Any products and services provided through this package are not supported or warrantied by Statistics Sweden.
See LICENSE for license details concerning this package. Read more about using Statistics Sweden's Open Data API here for details concerning the data provided by their API and license information.