Contents

imgly/imglyengine-swift

This package contains the Swift version of the IMG.LY _Creative Engine_, the core of CE.SDK.

License

The CreativeEditor SDK is a commercial product. You can purchase a license at https://img.ly/pricing. Alternatively, you can use nil as the license parameter to run the SDK in evaluation mode with a watermark.

Integration

SwiftUI

import IMGLYEngine
import SwiftUI

struct IntegrateWithSwiftUI: View {
  @State private var engine: Engine?

  var body: some View {
    Group {
      if let engine {
        ContentView(engine: engine)
      } else {
        ProgressView()
      }
    }
    .onAppear {
      Task {
        engine = try await Engine(license: secrets.licenseKey, userID: "<your unique user id>")
      }
    }
  }
}

struct ContentView: View {
  @StateObject private var engine: Engine

  init(engine: Engine) {
    _engine = .init(wrappedValue: engine)
  }

  var body: some View {
    ZStack {
      Canvas(engine: engine)
      Button("Use the Engine") {
        // do something with the instance of Engine
      }
    }
  }
}

UIKit

import IMGLYEngine
import MetalKit
import UIKit

class IntegrateWithUIKit: UIViewController {
  private var engine: Engine?
  private lazy var canvas = MTKView(frame: .zero, device: MTLCreateSystemDefaultDevice())
  private lazy var spinner = UIActivityIndicatorView()
  private lazy var button = UIButton(type: .system, primaryAction: UIAction(title: "Use the engine", handler: { [unowned self] _ in
      guard let engine else { return }
      // do something with the instance of Engine
  }

  override func viewDidLoad() {
    super.viewDidLoad()

    view.addSubview(canvas)
    view.addSubview(spinner)
    view.addSubview(button)
    // setup constraints

    spinner.startAnimating()
    spinner.hidesWhenStopped = true
    button.isHidden = true
  }

  // pass lifecycle events
  override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
     Task {
        engine = try await Engine(context: .metalView(view: canvas), license: secrets.licenseKey, userID: "<your unique user id>")
        engine?.onAppear()
        spinner.stopAnimating()
        button.isHidden = false
      }
  }

  override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    engine?.onDisappear()
  }
}

Documentation

The full documentation of IMGLYEngine can be found at here. There you will learn what configuration options are available and find a list and description of all API methods.

Changelog

To keep up-to-date with the latest changes, visit CHANGELOG.

Package Metadata

Repository: imgly/imglyengine-swift

Default branch: main

README: README.md