Skip to main content

Embed using SwiftUI

Since we are using UIKit in our example application we need to use an UIHostingController to present a SwiftUI View. The EmbeddedVideoEditorSwiftUIView defined below wraps the actual VideoEditor view to coordinate its dismissal with the presenting UIViewController. This process is not necessary for a pure SwiftUI application. You would use the VideoEditor view directly.

Embed in a NavigationView#

The custom EmbeddedVideoEditorSwiftUIView acts as the ContentView of a pure SwiftUI application.

First, we need to create a configuration object and set the navigationControllerMode to .useToolbar, since PhotoEditor SDK currently does not support displaying the toolbar in the navigation bar.

Refer to the configuration guide for a detailed explanation of how to configure the editor.

Next, we instantiate the VideoEditor inside a NavigationView with the provided video and pass the configuration object.

Handling events#

Using the onDidSave modifier allows us to register an event handler that is invoked when a user successfully exports an edited video. The result argument passed to the closure is of type VideoEditorResult and contains the URL of the exported video.

After performing some action with this video, such as uploading it or saving it, we call dismissAction to exit the editor.

Likewise, if the user taps the cancel button or an error was thrown we dismiss the editor in this example.

Next Steps#