This repository has been archived by the owner on Dec 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,66 @@ | ||
# Provincial | ||
|
||
Provincial is a small library to quickly get a list of states or provinces from various countries. | ||
|
||
## Goal | ||
|
||
Ultimately, the goal of Provincial was to provide a quick way to get a list of US states and Canadian provinces. Instead of hardcoding a list of strings in an array, this library can provide a list of `State` objects that give basic information about each. | ||
|
||
## Requirements | ||
|
||
None. | ||
|
||
## Installation | ||
|
||
[](http://cocoapods.org/pods/Provincial) | ||
[](http://cocoapods.org/pods/Provincial) | ||
[](http://cocoapods.org/pods/Provincial) | ||
|
||
Provincial is available through [CocoaPods](http://cocoapods.org). To install | ||
it, simply add the following line to your Podfile: | ||
|
||
```ruby | ||
pod "Provincial" | ||
``` | ||
|
||
## Usage | ||
|
||
At the top of your .swift file: | ||
``` | ||
import Provincial | ||
``` | ||
|
||
To get a list of all US states: | ||
``` | ||
let states = Provincial.states(in: .usa) | ||
``` | ||
This returns a list of `PoliticalEntity` objects representing states. | ||
|
||
The `PoliticalEntity` protocol requires each to provide a `State` computed property. This `State` struct includes the name and abbreviation of each state. Thus, to print the name of all 50 US States, you could write: | ||
``` | ||
for state in states { | ||
print(state.info.name) | ||
} | ||
``` | ||
|
||
States are listed by means of an enum. This can allow you to either check for specifics states while looping through a set, or to get individual information for a particular state. | ||
|
||
``` | ||
let arizona = USState.arizona | ||
print(arizona.name) | ||
print(arizona.abbreviation) | ||
``` | ||
|
||
It's also possible to filter or sort the array using Swift's built in `.filter` and `.sorted` methods. | ||
``` | ||
let newestStates = states.sorted { $0.info.date > $1.info.date } | ||
``` | ||
|
||
|
||
## Author | ||
|
||
Josh Hrach, josh.hrach@gmail.com | ||
|
||
## License | ||
|
||
Provincial is available under the MIT license. See the LICENSE file for more info. |