SwiftUI Development with the Native SDK for iOS

In this topic, you will be introduced to SwiftUI for developing apps with the Brightcove Native SDK for iOS/tvOS.


SwiftUI is a development framework that allows you to describe the UI and its behavior using structured statements. You can use this framework to create iOS, tvOS, iPadOS, watchOS, and macOS apps.

SwiftUI provides views, controls, and layout structures to declare your app UI. One of the benefits of using SwiftUI is the ability to see a real-time preview of your UI while you are coding.


This topic aims to introduce you to SwiftUI and provide an example of how you can use it when working with the Brightcove Native SDK for iOS. Continue learning about SwiftUI with these resources:

Create a new project

To get started, follow these steps to create a new SwiftUI project in Xcode.

  1. Open Xcode and select Create a new Xcode project.

    Welcome to Xcode
  2. Select iOS as the platform and App as the template. Click Next.

    Choose app template
  3. Set the project information as follows:

    • Product Name: Enter your project name (example: MySwiftUIPlayer)
    • Team: none

      The Team field is optional. If you want to distribute your app on the App Store, you will need to select a team that you belong to through the Apple Developer Program. The team name is required for code signing. In this example, we'll select none.

    • Organization Name: your company name
    • Organization Identifier: com.example-company
      This makes the product name unique for the app store.
    • Interface: SwiftUI
    • Language: Swift

    Click Next.

    Project options
  4. Choose the location where you want to save your project and create it.

  5. Now close the project (yes, close it — this is important!)

Add SDK dependencies

The easiest way to add the SDK and its dependencies to your project is to use CocoaPods.

CocoaPods is a dependency manager that adds libraries to your project. It is not required, but makes installation easier. To install CocoaPods, see the instructions on the CocoaPods site.

  1. In your project folder, create a plain text file called Podfile (no file extension).

  2. Using a text editor, add the following lines of code to the Podfile and save it. This code does the following:

    • Line 1: Points to the GitHub location for the CocoaPods pod specs
    • Line 2: Points to the GitHub location for the Brightcove pod specs
    • Line 4: Defines the iOS platform version
    • Line 5: Sets Pods to use frameworks instead of static libraries
    • Lines 7-12: Install the Brightcove Native Player SDK

    source 'https://github.com/CocoaPods/Specs.git'
    source 'https://github.com/brightcove/BrightcoveSpecs.git'
    platform :ios, '13.6'
    target 'MySwiftUIPlayer' do
      # Pods for MySwiftUIPlayer
      pod 'Brightcove-Player-Core/XCFramework'
  3. Open a Terminal session and navigate to your Xcode project folder.

  4. In the Terminal session, type the command

    pod install

    and press Return to run the it.

    If CocoaPods can not find a compatible version for the pod, or it is not the latest version, try running the following in the Terminal app:

    pod update

    You should see a series of messages in the terminal indicating that the Brightcove Player SDK has been added to your project.

  5. The pod install command creates the .xcworkspace file for your project.

    Notice the last line, which is important — from this point on, you must do the following:

    • Open the .xcworkspace file in Xcode
    • Do not use the .xcodeproj file
  • Now you are ready to code your app. To learn more about using SwiftUI, see the Resources section.
  • Code sample

    To help you with your app code, Brightcove has provided the following code sample: