简体   繁体   English

Swift 3 参数:单变量,两种类型

[英]Swift 3 Parameter: single variable, two types

Anyone know if there's a way to have a parameter be of two types?任何人都知道是否有办法让参数有两种类型?

Such as for the function:例如对于函数:

func email(from viewcontroller : (UIViewController, MFMailComposeViewControllerDelegate) {

}

Genericize your function's definition:泛化你的函数定义:

func email<T>(from viewController : T) where T: UIViewController, T: MFMailComposeViewControllerDelegate {
    // ...
}

In Swift 4在斯威夫特 4

func email(from viewcontroller : UIViewController & MFMailComposeViewControllerDelegate) {
}

Elegant, short and intuitive.优雅、简短且直观。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM