Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将此Objective-c转换为swift?[[xAudioPlayerHelper shareInstance]setDelegate:(id<;NSFileManagerDelegate>;)self];_Objective C_Swift - Fatal编程技术网

如何将此Objective-c转换为swift?[[xAudioPlayerHelper shareInstance]setDelegate:(id<;NSFileManagerDelegate>;)self];

如何将此Objective-c转换为swift?[[xAudioPlayerHelper shareInstance]setDelegate:(id<;NSFileManagerDelegate>;)self];,objective-c,swift,Objective C,Swift,但无法编译,错误为:委托使用不明确,是否shareInstance可能返回类型为id的对象?在这种情况下,编译器将不知道它得到的是什么类型,因此也不知道需要哪种类型的委托 如果是,则修改它以返回实例类型(如果可能);作为备用方案,执行以下操作: XHAudioPlayerHelper.shareInstance().delegate = self as! NSFileManagerDelegate 我的视图控制器已经有许多委托。ChatDetailsViewController.swift:3

但无法编译,错误为:委托使用不明确,

是否
shareInstance
可能返回类型为
id
的对象?在这种情况下,编译器将不知道它得到的是什么类型,因此也不知道需要哪种类型的委托

如果是,则修改它以返回
实例类型
(如果可能);作为备用方案,执行以下操作:

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

我的视图控制器已经有许多委托。ChatDetailsViewController.swift:374:68:Cast from'()->AnyObject!'对于不相关的类型“XhadioPlayerHelper”总是失败OC中的共享实例如下:
+(id)shareInstance{static XhadioPlayerHelper*instance=nil;static dispatch_once_t onceToken;dispatch_once(&onceToken,^{instance=[[XhadioPlayerHelper alloc]init];});return instance;}
我遗漏了一些括号;你明白我的意思吗
id
不会告诉编译器返回预期的类型。因此,它无法确定它将从
.delegate
.Thank:)中获得什么类型的对象。它现在可以工作了:
让sharedInstance=xAudioPlayerHelper.shareInstance()作为!xAudioPlayerHelper sharedInstance.delegate=self
XHAudioPlayerHelper.shareInstance().delegate = self as! NSFileManagerDelegate
let sharedInstance = XHAudioPlayerHelper.shareInstance() as! XHAudioPlayerHelper
sharedInstance.delegate = ...