Swiftpack.co -  kirualex/SwiftyGif as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
High performance GIF engine
.package(url: "https://github.com/kirualex/SwiftyGif.git", from: "5.4.0")

Language CocoaPods Compatible Carthage compatible Build Status Pod License


High performance & easy to use Gif engine


  • ☑ UIImage and UIImageView extension based
  • ☑ Remote GIFs with customizable loader
  • ☑ Great CPU/Memory performances
  • ☑ Control playback
  • ☑ Allow control of display quality by using 'levelOfIntegrity'
  • ☑ Allow control CPU/memory tradeoff via 'memoryLimit'


With CocoaPods

source 'https://github.com/CocoaPods/Specs.git'
pod 'SwiftyGif'

With Carthage

Follow the usual Carthage instructions on how to add a framework to an application. When adding SwiftyGif among the frameworks listed in Cartfile, apply its syntax for GitHub repositories:

github "kirualex/SwiftyGif"

With Swift Package Manager


How to Use

Project files

As of now, Xcode xcassets folders do not recognize .gif as images. This means you need to put your .gif oustide of the assets. I recommend creating a group gif for instance.

Quick Start

SwiftyGif uses familiar UIImage and UIImageView to display gifs.


import SwiftyGif

do {
    let gif = try UIImage(gifName: "MyImage.gif")
    let imageview = UIImageView(gifImage: gif, loopCount: 3) // Will loop 3 times
    imageview.frame = view.bounds
} catch {

Directly from nib/storyboard

@IBOutlet var myImageView : UIImageView!

let gif = try UIImage(gifName: "MyImage.gif")
self.myImageView.setGifImage(gif, loopCount: -1) // Will loop forever

Remote GIFs

// You can also set it with an URL pointing to your gif
let url = URL(string: "...")
let loader = UIActivityIndicatorView(style: .white)
cell.gifImageView.setGifFromURL(url, customLoader: loader)


A SwiftyGifManager can hold one or several UIImageView using the same memory pool. This allows you to tune the memory limits to you convenience. If no manager is declared, SwiftyGif will just use the SwiftyGifManager.defaultManager.

Level of integrity

Setting a lower level of integrity will allow for frame skipping, lowering both CPU and memory usage. This can be a good option if you need to preview a lot of gifs at the same time.

do {
    let gif = try UIImage(gifName: "MyImage.gif", levelOfIntegrity:0.5)
} catch {


SwiftyGif offer various controls on the current UIImageView playing your gif file.

self.myImageView.showFrameAtIndexDelta(delta: Int)
self.myImageView.showFrameAtIndex(index: Int)

To allow easy use of those controls, some utility methods are provided :

self.myImageView.isAnimatingGif() // Returns wether the gif is currently playing
self.myImageView.gifImage!.framesCount() // Returns number of frames for this gif


You can declare a SwiftyGifDelegate to receive updates on the gif lifecycle. For instance, if you want your controller MyController to act as the delegate:

override func viewDidLoad() {
        self.imageView.delegate = self

Then simply add an extension:

extension MyController : SwiftyGifDelegate {

    func gifURLDidFinish(sender: UIImageView) {

    func gifURLDidFail(sender: UIImageView) {

    func gifDidStart(sender: UIImageView) {
    func gifDidLoop(sender: UIImageView) {
    func gifDidStop(sender: UIImageView) {


Display 1 Image

CPU Usage(average) Memory Usage(average)
FLAnimatedImage 35% 9,5Mb
SwiftyGif 2% 18,4Mb
SwiftyGif(memoryLimit:10) 34% 9,5Mb

Display 6 Images

CPU Usage(average) Memory Usage(average)
FLAnimatedImage 65% 25,1Mb
SwiftyGif 22% 105Mb
SwiftyGif(memoryLimit:20) 45% 26Mb

Measured on an iPhone 6S, iOS 9.3.1 and Xcode 7.3.


Stars: 1406
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

25 weeks ago
  • FIxed : Gif animations play at different speeds on iPad vs iPhone
  • FIxed : method "gifDidStop" will execute twice
  • Added : basic support for macOS
  • Changed : bump IPHONEOS_DEPLOYMENT_TARGET to 9.0 to remove warning
  • Changed : Removed big files from repo

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API