HomeiOS Developmentswift - iOS - SwiftUI inside a UIKit View utilizing AudioKit

swift – iOS – SwiftUI inside a UIKit View utilizing AudioKit


I am pretty new to Swift and MVVM, so my apologies if I misunderstand a few of the structure right here and say one thing fully incorrect.

I’ve an app written in Swift utilizing UIKit with a primary view controller that generates some sounds utilizing AudioKit. I would like so as to add a visualizer to that view, and it appears acceptable to make use of the AudioKitUI library to generate a visualization from the audio that my app is producing whereas in that storyboard view.

Many of the AudioKitUI stuff appears to be in SwiftUI on the backend. I’ve checked out utilizing a UIHostingController however I get an error that the initializer is inaccessible resulting from inner safety stage. If I copy/paste the SpectrogramView.swift from the AudioKitUI GitHub right into a swift file, I’m able to generate a preview efficiently.

spectrogram view

I attempted to place it right into a UIHostingController inside a Container View, however I did not precisely see how I ought to have the spectrogram learn the audio node in actual time if it isn’t in that view. So it put the UIHostingController inside my primary view controller, added it as a baby view, and added it as a subview to a clean UIView.

I am undecided the best way to get this SwiftUI Visualization generator to work with UIKit, not to mention inside considered one of my ViewController’s sub views. Any suggestions or recommendation could be tremendously appreciated.

This was my most up-to-date try:

@IBOutlet var blankView: UIView!


override func viewDidLoad() {
    tremendous.viewDidLoad()
    let spectroView = UIHostingController(rootView: SpectrogramView(node: sound.mixer))
    addChild(spectroView)
    blankView.addSubview(spectroView.view)
    }

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments