如何使struct和typealias符合@objc

时间:2016-06-06 21:42:22

标签: swift swift-protocols

是否可以使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
    }

1 个答案:

答案 0 :(得分:3)

您无法将类型比例导出到Objective-C。你不能为元组做这件事。但是,关于typealias,仍然可以为某些结构编写Obj-C typedef并在Swift中使用它,它将导出为typealias