An existing Sendbird project or a brand new Swift UI Project along these instructions
First add the Sendbird UIKit dependency to your Cocoapod .podspec file (for instructions using Carthage, see here):
Make sure the minimum platform version is 10.3 or higher:
platform :ios, '10.3'
Then run `pod install`
Sendbird’s UIKit was originally created with Apple’s UIKit so you’ll need to create a UIViewControllerRepresentable struct that returns a UIViewController class.
1. Start by creating a new swift file and name it `ChannelListView.swift`
3a. Add an objective-c function to create an instance of UINavigationController with Sendbird’s SBUCHannelListViewController as the root view controller.
3b. Call this function within a `viewDidAppear` override block
4a. Set the UIViewControllerType typealias to the ChannelListViewController class above
4b. Have the required makeUIViewController function return an instance of the ChannelListViewController class
4c. Add the required updateUIViewController function – but can leave empty
In the default `ContentView.swift` file we’ll be doing the following in the init() block:
1. Initializing the Sendbird SDK using `SBUMain.initialize()`, passing in an application id*.
Followed by 4. updating the body property to make use of the `ChannelListViewController` we created earlier.
*Your application id can be found or created through the Sendbird dashboard:
**Note that if the app id is invalid or we otherwise encounter a connection error, an instance of an SBDUser will not be returned in the completion handler.
If you use a valid application id then build and run onto a simulator or device, you will see the following screen:
UIKit is now up and running in your SwiftUI application.
Use the button to create a new Group Channel with another test user. You will need at least 2 users in your app before any will appear in a SBUCreateChannelViewController (or SBUInivteUserViewController or SBUMemberListViewController?) view instance that is automatically created by UIKit:
Select a few users to create a channel with then click the “Create” button to automatically open up an instance of a SBUChannelViewController view. Once you’ve sent a few messages between your users you will see something like:
All the code presented here can be found in this demo repo.
In this tutorial we covered: