Mac Mac - 2 months ago 13
Swift Question

"Ambiguous Reference To" Error in Swift 3

Good Afternoon,

Im attempting to code a Music Play Application in which I am trying to implement some Open Source Code entitled "STK Audio Player" which is coded in Objective C.

When attempting to call a Method from the imported Source, I receive the following compile error.

"Ambiguous Reference To Member Play"

import UIKit

class ViewController: UIViewController {

var audioPlayer = STKAudioPlayer()


override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

let songToPlay:String = "http://themarketshop.com/beats/fatbeat.mp3"

STKAudioPlayer.play(songToPlay)
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


}

From The Open Source

/// Plays an item from the given URL string (all pending queued items are removed).
/// The NSString is used as the queue item ID
-(void) play:(NSString*)urlString;

Answer

play is an instance (-) method, so use the instance:

audioPlayer.play(songToPlay)

and do not annotate literal strings as String. Everybody including the compiler can see what it is.

Comments