In this tutorial: https://swiftui-lab.com/swiftui-animations-part4/
I'm trying to run the metronome, about 1/2 way down the page. It's a simple call to NSSound and I get an error cannot find the type. I change that type to "Any" and then it doesn't find NSSound. I think it should be apart of UIKit, but it doesn't seem to be working.
Q. How can I run NSSound() in an iOS, SwiftUI app?
Other imports don't resolve the error:
import UIKit
import AudioUnit
import AVFAudio
import AVFoundation
import AVKit
import AudioUnit
import CoreAudio
import Foundation
let bellSound: NSSound? = {
guard let url = Bundle.main.url(forResource: "bell", withExtension: "mp3") else { return nil }
return NSSound(contentsOf: url, byReference: true)
}()
CodePudding user response:
NSSound
is only available in macOS
environment(actually macOS 10
. Not in iOS
environment. Check the documentation here for further details.