Reputation: 1603
I've some simple sounds and I have multiple View Controllers and I wonder how to use sounds in every controller in my app. Should I create an extension, protocol, struct or something else? What would be the best OOP approach? There are plenty of tutorials but none of them shows how to efficiently use sounds in your app.
Upvotes: 0
Views: 55
Reputation: 1111
With your context, I suggest you to write something like SoundService, and declare it as a singleton. So every controller has the access to this service. The parameter for the service is something like sound file names.
This service will be used in the app, anytime the controller wants to play a sound, just call a method in the singleton. That will make your code looks better, and if you find any problem related to Sound, you know where to find the problem.
Upvotes: 1