Swift
For Swift apps, use humation-swift. It renders the same avatars as the web packages.
humation-swift is a native port of the engine. A seed picks parts with the same hash as @humation/core, so the same seed gives the same avatar on the web and in a native app.
It renders with Core Graphics, without a WKWebView or network access, and bundles the Humation 1 asset package.
Install
Add the package with Swift Package Manager, then add the Humation product to your target.
.package(url: "https://github.com/humation-labs/humation-swift.git", from: "1.3.0")
humation-swift is versioned separately from the npm packages.
Render from a seed
import Humation
HumationAvatarView(seed: user.id, size: 96)
Image output, saved profiles, the built-in editor, and custom manifests are covered in the humation-swift README.
Share avatars with the web
Swift stores a user’s avatar as HumationProfile, which encodes to JSON with selections and colors. It differs from the web packages in a few places, so check these when the same data is used on both sides.
- Swift accepts canonical IDs such as
hm1-p-000020only. Part names and aliases such asbraidsare not resolved.toJSON()in@humation/corereturns canonical IDs, andresolvePartIdconverts a name to its ID. - Swift stores the background color as
colors.background. The web packages take it as the separatebackgroundoption and ignorebackgroundinsidecolors. - A seed picks from the list of parts, so use the same version of the assets on both sides. humation-swift 1.3.0 bundles
@humation/assets-humation-11.0.3.