htmlcat
htmlcat

Reputation: 336

How to make a NSSound loop

I'm attempting to make a simple application on XCode (in Swift) that plays an audio file, then keeps looping infinitely. According to Apple's website, I need to add var loops: Bool { get set } to my code; but I'm not sure how to combine that with my current code in a way that doesn't give an error.

This is what I have so far:

let song = NSSound(named: "song.mp3")?.play()
var loops: Bool { get set }

Upvotes: 2

Views: 195

Answers (1)

Evgeny Karkan
Evgeny Karkan

Reputation: 9612

Try in this way:

// create an instance    
let song = NSSound(named: "song.mp3")

// set `loops` property to be true    
song?.loops = true

// start to play   
song?.play()

Upvotes: 2

Related Questions