Open the SWookiee.xcworkspace
and run the sample application shown above. It's a fun experience that demonstrates usage of the library.
You might have trouble if you haven't set up Xcode with Github credentials since the app uses SPM to fetch repos.
Use Swift Package Manager to install the SWookiee
package.
The API is simple and allows access to SWAPI resources.
All of the major Resource
types and structs available are:
- Root - fetches the root resources from SWAPI
- Film - fetches the film resources
- Person - fetches the people resources
- Planet - fetches the planet resources
- Species - fetches the species resources
- Starship - fetches the starship resources
- Vehicle - fetches the vehicle resources
For full details on which endpoints are used, check Endpoint.swift
.
The common method for fetching data, for example the films would be like this:
Film.fetch { result in
guard case .success(let films) = result else {
// Deal with failure
return
}
// Do something with `films` list
}
Each resource can access related resources as well simply via Provider
methods. For example, to get characters
for a film, you can do:
film.characters { result in
// Process list of characters or error
}
All completion handlers may be called on a background thread, so if you're updating UI, be sure to dispatch back onto the main queue.
The library caches responses by default, so subsequent requests don't reach out to the network. This may or may not be ideal but future changes can make this functionality more configurable.
Additionally, when you call fetch
on any of the Resource
types, it will follow pages automatically as well and get all the available data from SWAPI. Again, this may or may not be ideal, but can be augmented in the future.
The app tries to search for images from Pixabay so you'll need to update ImageService
with an API key. Otherwise, the images feature will not work.
Contributions are what makes the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (git checkout -b feature/AmazingFeature)
- Commit your Changes (git commit -m 'Add some AmazingFeature')
- Push to the Branch (git push origin feature/AmazingFeature)
- Open a Pull Request
Distributed under the MIT License.