是否可以使struct
和/或typealias
符合@objc
?我希望创建可选的协议功能,一个返回struct
,另一个返回typealias
。
public typealias SwiperData = (image: UIImage, title: String)
public struct SwiperPeekViewControllers{
public var parentViewController: UIViewController!
public var contentViewController: UIViewController!
public init(parentVC: UIViewController, contentVC: UIViewController){
parentViewController = parentVC
contentViewController = contentVC
}
}
协定
@objc public protocol SwiperPeekViewDelegate: class{
func didUndoAction(index: Int, dataSource: SwiperData)
// Method cannot be a member of an @objc protocol because the type of the parameter 2 cannot be represented in Objective-C
func swiperPeekViewControllers()->SwiperPeekViewControllers
func swiperPeekViewSize()->CGSize
}
答案 0 :(得分:3)
您无法将类型比例导出到Objective-C。你不能为元组做这件事。但是,关于typealias
,仍然可以为某些结构编写Obj-C typedef
并在Swift中使用它,它将导出为typealias