Skip to content

Latest commit

 

History

History
82 lines (53 loc) · 3.82 KB

README.md

File metadata and controls

82 lines (53 loc) · 3.82 KB

SWookiee

animated

The App

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.

Installation

Use Swift Package Manager to install the SWookiee package.

API

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.

Cache

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.

Image Search

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.

Contributing

Contributions are what makes the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License.

If You ♥️ What We Do

Buy Me A Coffee