Alex L
Alex L

Reputation: 309

How can I convert this Objective-c to swift? [[XHAudioPlayerHelper shareInstance] setDelegate:(id<NSFileManagerDelegate>)self];

[[XHAudioPlayerHelper shareInstance] setDelegate:(id<NSFileManagerDelegate>)self];

I want to translate this OC to swift.

I tried that :

XHAudioPlayerHelper.shareInstance().delegate = self as! NSFileManagerDelegate

But couldn't compiled with error of : ambiguous use of delegate,

Upvotes: 0

Views: 95

Answers (1)

Tommy
Tommy

Reputation: 100662

Does shareInstance perchance return an object of type id? In that case the compiler would have no idea what type it is getting and hence which type of delegate is expected.

If so then amend it to return instancetype if possible; as a fallback perform something like:

let sharedInstance = XHAudioPlayerHelper.shareInstance() as! XHAudioPlayerHelper
sharedInstance.delegate = ...

Upvotes: 2

Related Questions