Swiftpack.co -  Package - znly/Looping
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
A simple and lightweight framework to display looping images using native UIKit and SwiftUI
.package(url: "https://github.com/znly/Looping.git", from: "1.1.1")


License SwiftPM Support Carthage Support

What is Looping?

A simple and lightweight framework to display looping images using native UIKit and SwiftUI.

Supported formats

Out of the box, Looping supports 3 formats of animated and still images: GIF, APNG and HEIC.

To add WebP support, include the framework LoopingWebP, and enable it once:

import Looping
import LoopingWebP



Next steps

  • CocoaPod support.
  • Unit tests coverage.
  • BackgroundBehavior (restart, stop, resume).
  • Progressive decoding option.
  • Native support on macOS, watchOS, tvOS.

Minimum deployment targets

  • iOS 11
  • macOS 10.15

Project requirements

  • Xcode 11 (swift 5.1)



Swift Package Manager (SwiftPM) is dependency manager as well as a distribution tool.

From Xcode 11 onward, SwiftPM is natively integrated with Xcode. In File -> Swift Packages -> Add Package Dependency, search for WebPImage's repo URL.

If you're a framework author, you can add following the dependency to your Package.swift:

dependencies: [
    .package(url: "https://github.com/znly/Looping.git", .from("0.1.0"))


Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

To integrate Looping into your Xcode project using Carthage, specify it in your Cartfile:

github "znly/Looping" ~> 0.1.0


① Creating a LoopImage

The prefered method is to use init(data:, scale:). Default scale is 1.0.

import Looping

let imageData: Data
let image = try? LoopImage(data: imageData)

Additional convenience initializers are available: init(url:) and init(named:). Note: If the file name contains a scale factor (eg: @{1,2,3}x) it will be applied to the image.

② Displaying a LoopImage

Rendering happens on a background thread.

Using LoopView (UIKit)

import Looping

let image: LoopImage
let imageView = LoopView(loopImage: image)

loopView.contentMode = .scaleAspectFit
loopView.loopMode = .once

Using Loop (SwiftUI)

import Looping

let image: LoopImage

struct ContentView: View {
    var body: some View {

③ Converting a LoopImage frame into a UIImage or CGImage

Using either the methods for a single frame LoopImage.cgImage(atFrame:) and LoopImage.image(atFrame:), or for a range of frames LoopImage.cgImages(atRange:).

For WebP images, since retrieving the image of at a specific frame requires to go over every intermediary frame to reconstruct the final image, it is recommended to call these methods outside of the main thread.

import Looping

let loopImage: LoopImage
let cgImage: CGImage = loopImage.cgImage()
let image: UIImage = loopImage.image() // alternatively you can use UIImage(loopImage: loopImage)


Looping documentation can be found at znly.github.com/Looping.

Generated using SwiftDoc.


See AUTHORS for the list of contributors.


Assets used in the example app are taken from:


The Apache License version 2.0 (Apache2) - see LICENSE for more details.

Copyright © 2020 Zenly hello@zen.ly @zenlyapp


Stars: 17
Last commit: 2 weeks ago

Related Packages

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