Appearance
Getting Started on Swift
This guide will walk you through the steps to integrate RecordKit into your Swift app. By the end you will be able to make a screen recording.
Starting from scratch?
- Start Xcode choose "Create New Project..." from the launch screen.
- Choose macOS, select App and click Next.
- Make sure to choose SwiftUI as interface setting and Swift for the language.
When finished a new Xcode project will open, you can now continue this Getting Started guide.
1. Adding RecordKit
RecordKit for Swift is installed as a SPM (Swift Package Manager) package.
- Choose File, Add Package Dependencies...
- Enter the RecordKit package URL in the search field top right:
https://github.com/nonstrict-hq/RecordKit
- Select RecordKit from the list and choose Add Package.
Make sure the RecordKit library is added to your macOS app target.
2. Start a recording
- Discover the devices, windows or displays to record.
Swift
let windows = try await RKRecorder.getWindows()
let cameras = RKRecorder.getCameras()
let microphones = RKRecorder.getMicrophones()
let appleDevices = await RKRecorder.getAppleDevices() // iPhones, iPads, etc.
- Configure & start a recorder
Swift
// Configure the recorder
let recorder = RKRecorder([
.windowBasedCrop(windowID: windows.first!.id),
.webcam(microphoneID: microphones.first!.id, cameraID: cameras.first!.id),
.appleDeviceStaticOrientation(deviceID: appleDevices.first!.id)
])
// Calling prepare is highly recommended, this activates all devices and makes sure a call to start will start the recording instantly.
// (Screen recording & camera indicators will be visible to the user after calling prepare, also permission alerts might be triggered.)
try await recorder.prepare()
// Actually start recording
recorder.start()
- Finish the recording
Swift
// Stop the recording, returns information about the recording
let result = try await recorder.stop()