2025-09-12 00:51:06 +00:00
[](https://swiftpackageindex.com/rock-n-code/amiibo-service)
[](https://swiftpackageindex.com/rock-n-code/amiibo-service)
2025-10-07 22:32:54 +00:00
# Amiibo Service
2026-09-14 10:13:41 +00:00
A Swift client for the [Amiibo API ](https://www.amiiboapi.org ).
## Requirements
- Swift 6.2 or later
- iOS 13, macOS 10.15, tvOS 13, visionOS 1, or watchOS 6 or later
2025-09-09 18:34:29 +00:00
## Installation
2026-09-14 10:13:41 +00:00
Add the package and the `AmiiboService` product to `Package.swift` :
2025-09-09 18:34:29 +00:00
```swift
let package = Package (
// name, platforms, products, etc.
dependencies : [
2026-09-14 10:13:41 +00:00
. package ( url : "https://github.com/rock-n-code/amiibo-service" , from : "2.0.0" ),
2025-09-09 18:34:29 +00:00
],
targets : [
. target (
2026-09-14 10:13:41 +00:00
name : "SomeTarget" ,
2025-09-09 18:34:29 +00:00
dependencies : [
. product ( name : "AmiiboService" , package : "amiibo-service" ),
]
2026-09-14 10:13:41 +00:00
),
2025-09-09 18:34:29 +00:00
]
)
```
2026-09-14 10:13:41 +00:00
In Xcode, add the package URL under **File › Add Package Dependencies…** .
2026-03-22 23:39:48 +00:00
## Usage
```swift
import AmiiboService
let service = AmiiboService ()
2026-09-14 10:13:41 +00:00
// All amiibos
2026-03-22 23:39:48 +00:00
let amiibos = try await service . getAmiibos ()
2026-09-14 10:13:41 +00:00
// Amiibos whose name contains "zelda"
2026-03-22 23:39:48 +00:00
let zeldaAmiibos = try await service . getAmiibos (. init ( name : "zelda" ))
2026-09-14 10:13:41 +00:00
// Amiibo series, types, game characters, and game series
2026-03-22 23:39:48 +00:00
let series = try await service . getAmiiboSeries ()
let types = try await service . getAmiiboTypes ()
let characters = try await service . getGameCharacters ()
let gameSeries = try await service . getGameSeries ()
2026-09-14 10:13:41 +00:00
// Date of the last data update (UTC)
2026-03-22 23:39:48 +00:00
let lastUpdated = try await service . getLastUpdated ()
```
2026-09-14 10:13:41 +00:00
Results are sorted in ascending order by identifier (amiibos) or key (everything else).
## Error handling
Every call throws `AmiiboServiceError` . When nothing matches, `getAmiibos(_:)` returns an empty array, while the other list calls throw `AmiiboServiceError.notFound` :
```swift
do throws ( AmiiboServiceError ) {
let series = try await service . getAmiiboSeries (. init ( key : "0x01" ))
} catch . notFound {
// No amiibo series has this key.
} catch {
// .badRequest, .cancelled, .decoding, .notAvailable, .undocumented, or .unknown
}
```
2026-03-22 23:39:48 +00:00
## Caching
2026-09-14 10:13:41 +00:00
The library has no built-in cache. The Amiibo API asks regular consumers to cache responses. To do that, give `AmiiboLiveClient` a transport backed by a `URLCache` :
2026-03-22 23:39:48 +00:00
```swift
import OpenAPIURLSession
let configuration = URLSessionConfiguration . default
configuration . urlCache = URLCache (
memoryCapacity : 5_000_000 ,
diskCapacity : 50_000_000
)
let transport = URLSessionTransport (
configuration : . init (
session : URLSession ( configuration : configuration )
)
)
let service = AmiiboService (
client : AmiiboLiveClient ( transport : transport )
)
```
## Testing
2026-09-14 10:13:41 +00:00
To test without network access, pass a mock `AmiiboClient` to `AmiiboService(client:)` . `AmiiboClient` refines `Sendable` , so the mock must be `Sendable` , too:
2026-03-22 23:39:48 +00:00
```swift
import AmiiboService
2026-09-14 10:13:41 +00:00
struct MockClient : AmiiboClient {
2026-03-22 23:39:48 +00:00
var error : AmiiboServiceError ?
func getAmiibos (
by filter : AmiiboFilter
) async throws ( AmiiboServiceError ) -> [ Amiibo ] {
if let error { throw error }
return []
}
2026-09-14 10:13:41 +00:00
// Implement the remaining requirements...
2026-03-22 23:39:48 +00:00
}
2026-09-14 10:13:41 +00:00
let service = AmiiboService ( client : MockClient ())
2026-03-22 23:39:48 +00:00
```
2025-09-09 18:34:29 +00:00
2026-09-14 10:13:41 +00:00
## Development
2026-07-26 09:56:32 +00:00
2026-09-14 10:13:41 +00:00
Run `make` to list the available tasks for building, testing, and generating documentation.
The test suite runs offline by default. Tests against the live service run only if `AMIIBO_LIVE_TESTS` is set to `1` :
2026-07-26 09:56:32 +00:00
```shell
AMIIBO_LIVE_TESTS = 1 swift test
```
2026-09-14 10:13:41 +00:00
In Xcode, set the variable in the scheme's **Test** action.
2026-07-26 09:56:32 +00:00
2025-09-09 18:34:29 +00:00
## Documentation
2026-09-14 10:13:41 +00:00
See the [online documentation ](https://rock-n-code.github.io/amiibo-service/documentation/amiiboservice/ ).