Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.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/8/swift/16.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
Ios 如何声明符合协议的显式类型?_Ios_Swift - Fatal编程技术网

Ios 如何声明符合协议的显式类型?

Ios 如何声明符合协议的显式类型?,ios,swift,Ios,Swift,我试图在Swift中复制以下Objective-C代码: UIViewController <UIImagePickerControllerDelegate> *delegate = ... UIViewController*委托=。。。 我尝试了让委托:UIViewController!,UIImagePickerControllerDelegate,但XCode抱怨“模式中缺少类型注释”。仅让委托:UIImagePickerControllerDelegate 我不知道你为什

我试图在Swift中复制以下Objective-C代码:

UIViewController <UIImagePickerControllerDelegate> *delegate = ...
UIViewController*委托=。。。

我尝试了
让委托:UIViewController!,UIImagePickerControllerDelegate
,但XCode抱怨“模式中缺少类型注释”。

让委托:UIImagePickerControllerDelegate


我不知道你为什么要给代理一个类型。我们关心的只是它是否符合协议。您会注意到,由于这个原因,所有objective-c委托都是
id
,因此任何符合条件的对象都可以是委托。

委托也是视图控制器,我希望编译器在传入不同类型时作出响应。@Pétur
让委托:UIViewController
只要
UIViewController
符合您的协议权限,就有效,但我希望确保它确实有效。类似问题如下:。