How to play a sound indefinitely in an iOS app

I am currently doing a Udacity course in which I need to post how I can add functionality to an iOS app we’re building to play sound. So, I decided to write a post regarding how to play a sound indefinitely, given that I was previously shown how to play a sound slowly and quickly using the AVAudioPlayer class.

I reviewed the AVAudioPlayer class reference guide, and I found a property called numberOfLoops. The documentation indicates that numberOfLoops is a variable that can be set to an Int value. If you want to play the sound indefinitely, set any negative integer. This is exactly what I’d like to do, so I decided to use -1 as my value. You can see it below in my playAudioAtRate function that is called when playing sounds via my PlaySoundsViewController (compatible with Xcode 7.2 and Swift 2.1).

Screen Shot 2016-03-22 at 3.02.34 PM