A Swift framework for interacting with the Star Wars API (SWAPI). The framework includes data models for all resources provided by the API (e.g., films, people, planets, starships, and vehicles) as well as networking components and parsing to make requesting resources as simple as importing the framework.
SwapiSwift requires iOS 13+ and is built using Apple's Combine framework, making it suitable for SwiftUI projects.
You can install SwapiSwift manually or using Carthage.
Carthage is a simple dependency management system. To integrate SwapiSwift, specify the following in your project's Cartfile:
github "bratwursted/swapi-swift"
You can read more about installing Carthage locally at their repo.
If you prefer, you can include SwapiSwift manually as a submodule or just by copying the files to your project.
- Be sure your project directory is initialized as a git repository:
$ git init
- Add the repo as a submodule:
$ git submodule add https://github.com/bratwursted/swapi-swift
-
Open the
SwapiSwiftdirectory and drag theSwapiSwift.xcodeprojfile into the project navigator of your Xcode project. It should be nested under the main project project icon of your project. -
Verify the deployment target of your project application matches the target of
SwapiSwift.xcodeproj. -
Select the application target of your project and open the "General" tab. In the "Embedded Binaries" section, click the
+button and select theSwapiSwift.xcodeprojto add the framework to your Xcocde project.
The repo includes an example app to demonstrate how to incorporate SwapiSwift into a app. The primary components that are of interest are:
-
SwapiServicedefines a protocol with methods for requesting resources from the Star Wars API.DataServiceis a concrete implementation of the protocol, or you can create your own.MockDataServiceis an implementation that can be used to mock data for use in SwiftUI previews and unit tests. -
GraphServicedefines a protocol for helper classes that fill out the object graph for resources such as films, people and planets.MockGraphDataServiceis an implementation conforming toSwapiServicethat can be used to supply mock data for SwiftUI previews and unit tests.
For users of Paw, an API tool for Macs, the repo includes a .paw file so you can interact with the Star Wars API and inspect the API responses. There is also a swapi.json file that can be imported into Postman.
If you run into problems, find bugs, or would like to request a new feature, feel free to open an issue. If you'd like to contribute, put up a pull request 🎉.
The Star Wars API is an open source project from Paul Hallett.