Thomas Patterson
Thomas Patterson

Reputation: 43

SwiftUI add sound effect when a button is pressed

I would like to add a sound effect when a button is pressed in my app for SwiftUI. The button has another feature, but I just want to add a sound effect. I have found information for previous versions of Xcode using UIkit, but I'm not understanding how to do it in SwiftUI.

Edit: I'm very new to programming if that explains my lack of knowledge.

Upvotes: 4

Views: 7937

Answers (1)

from answer: Play reminder sound SwiftUI

you can use this simple method:

import AVFoundation

AudioServicesPlaySystemSound(1026)

where the number 1026 is the SystemSound id.

Upvotes: 14

Related Questions