This is just a direct port of the Objective-C++ code to Swift 6. A future patch should probably update it to actually use SwiftUI.