Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make struct and typealias conform to @objc

Is it possible to make a struct and/or typealias conform to @objc? I wish to create optional protocol functions, one returns a struct, the other a 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
  }
}

protocol

    @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
    }
like image 319
kye Avatar asked Jun 06 '16 21:06

kye


1 Answers

You can't export typealiases to Objective-C. And you can't do it for tuples. But, about typealias, it's still possible to write Obj-C typedef for some struct and use it from Swift, it will be exported as typealias

like image 129
Alex Nazarov Avatar answered Sep 29 '22 13:09

Alex Nazarov