Documentation

Add GIFs to your SwiftUI app

A native picker for iOS, plus an async Foundation client when you want to build your own interface.

1. Add the Swift package

In Xcode, choose File → Add Package Dependencies and paste this repository URL. Select version 0.1.1 or later, then add the GifSnapUI product to your app target. Add GifSnap too when using its models or client directly.

Swift Package Manager URL
https://github.com/rowixgroup/gifsnap-swift

Requires Swift 5.9 or later. The picker supports iOS 16 and later; the Foundation client supports iOS 16 and macOS 13 and later.

2. Show the picker

Use the selection callback to attach a GIF to your message or composer. Your app owns what happens after selection.

GIFComposer.swift
import SwiftUI
import GifSnapUI

struct GIFComposer: View {
    var body: some View {
        GifSnapPicker { gif in
            print(gif.url)
        }
    }
}

3. Keep the selected media

The callback returns a GifSnapGif with its title, full media URL, preview, dimensions and source metadata. Keep the object together when storing or sending a selection.

A stateful composer
import SwiftUI
import GifSnap
import GifSnapUI

struct MessageComposer: View {
    @State private var selected: GifSnapGif?

    var body: some View {
        VStack {
            GifSnapPicker(theme: .system, pageSize: 24) { gif in
                selected = gif
            }
            Text(selected?.title ?? "Choose a GIF")
        }
    }
}

Stickers, themes and your own UI

Pass mediaType: .sticker to browse stickers, initialQuery: "celebrate" to start with a search, or theme: .dark to follow an app-specific theme. The default .system appearance follows the device.

Foundation client
import GifSnap

let client = try GifSnapClient()
let response = try await client.search(
    query: "hello", page: 1, limit: 12
)
let gifs = response.data
let nextPage = response.pagination.nextPage

// Also available:
let stickers = try await client.searchStickers(query: "hello")
let trending = try await client.trending()

Use the client from an async task and handle thrown errors. Cancel work when the query or screen changes. The picker handles this for its own searches.

Animated media, correctly displayed

The picker uses SDWebImage’s native animated image view for GIF and animated WebP playback. It loads the full media URL first and uses the preview only if the full media fails. A preview may be a still image.

For a custom media view, use an animation-capable decoder. SwiftUI’s standard AsyncImage alone is not an animated GIF player. Preserve the URL, including its query string, and reserve space using the returned dimensions.

The API currently works without a key. The SDK code is MIT licensed; returned media keeps its own applicable rights and attribution. See the package README for dependency licenses and the complete API.

Source, releases and full Swift reference ↗ · Shared response and pagination reference