SwiftUI module
info
The SwiftUI module is optional. It is a thin wrapper around the UIKit SDK for SwiftUI apps on iOS 17+. The underlying playback engine, ad pipeline, and Cast support are identical. Most apps can use either; SwiftUI is the right choice only when your app is already SwiftUI-first and you target iOS 17 or newer.
What this module gives you
- A native SwiftUI
View(BBNativePlayer) that integrates with.aspectRatio,.frame,.padding, navigation,.id(...), sheets, etc. - Reactive state via
BBPlayerState(uses the@Observablemacro — per-property tracking; only the views that read a given property re-render when it changes). - Type-safe options (
BBPlayerOptions,BBShortsOptions) instead of an untyped[String: Any]dictionary. - Automatic lifecycle: the convenience initializer destroys the underlying SDK view on
.onDisappear. - The same surface for Shorts (
BBNativeShorts,BBShortsState,BBShortsOptions) and outstream renderers (BBNativeRenderer,BBRendererState).
What it does NOT give you
- New playback features. This is a wrapper, not a fork. Anything the UIKit SDK can't do, the SwiftUI module can't do either.
- iOS 16 or earlier compatibility.
@Observablerequires iOS 17+, Swift 5.9+, Xcode 15+. If you need to support older OS versions, use the UIKit SDK. - A reason to migrate working UIKit code. Both modules ship in the same Swift package — you can introduce SwiftUI views in a UIKit app or vice versa without picking one for the whole codebase.
When to choose SwiftUI
| If your app is… | Recommendation |
|---|---|
| Pure SwiftUI, iOS 17+ | Use the SwiftUI module. |
| Pure SwiftUI, iOS 16 or earlier | Use the UIKit SDK with UIViewControllerRepresentable. |
| Mixed UIKit + SwiftUI | Either works. Pick per-screen based on the surrounding code. |
| UIKit-only | Use the UIKit SDK. The SwiftUI module is irrelevant. |
What's in this section
- Getting Started — install via SPM or CocoaPods, add
BBNativePlayerto a view, observe state, control playback, switch clips, present modal players, render outstream ads. - Shorts — full guide to
BBNativeShorts(vertical swipe video / shelf carousel).
The auto-generated API reference for the SwiftUI module types is under the API Reference → BBNativePlayerKit-SwiftUI sidebar.