Swift Sound on repeat
Just set the numberOfLoops property to a negative number.
ThemePlayer.numberOfLoops = -1
From the documentation:
numberOfLoops The number of times a sound will return to the beginning, upon reaching the end, to repeat playback.
...
var numberOfLoops: Int
...
A value of 0, which is the default, means to play the sound once. Set a positive integer value to specify the number of times to return to the start and play again. For example, specifying a value of 1 results in a total of two plays of the sound. Set any negative integer value to loop the sound indefinitely until you call the stop method.
You may also need to make your AVAudioPlayer a property, rather than a local variable. As it stands, with automatic reference counting, I think your local ThemePlayer instance is likely to be deallocated by ARC. Someone who knows AVAudioPlayer better than me might be able to comment on that.
(As an aside, you might want to follow Apple's convention of naming object instances by starting with lowercase letters, e.g. themePlayer
rather than ThemePlayer
. It'll make your code easier for other people to read.)