1

How do I convert this code to Swift

 typedef  UIViewController<CalendarViewControllerNavigation> CalendarViewController;

tried to find solution everywhere but seems I can't find a reference to this.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Thanh
  • 65
  • 2
  • 10
  • 1
    You used the `typealias` tag for your question. So you seem to already know the answer. – rmaddy Apr 03 '17 at 23:08
  • Swift doesn't currently support expressing the type of something that inherits from a class and conforms to a given protocol – but [it will in a future version of the language](https://github.com/apple/swift-evolution/blob/master/proposals/0156-subclass-existentials.md). – Hamish Apr 03 '17 at 23:24
  • Do you any other way I can do that. Maybe create extension of UIViewController pressing protocol the typealias to that extension? – Thanh Apr 04 '17 at 01:19

2 Answers2

1

In Swift 4 you can use:

typealias CalendarViewController = UIViewController & CalendarViewControllerNavigation

Which uses the new protocol composition type. Also see SE-156.

Sulthan
  • 128,090
  • 22
  • 218
  • 270
0

I was facing same issue to use calendar library from https://github.com/jumartin/Calendar.

I have solved this problem as below.

protocol CalendarViewControllerNavigation: NSObjectProtocol {
    func move(to date: Date, animated: Bool)
}

typealias CalendarTypeController = UIViewController

extension CalendarTypeController:CalendarViewControllerNavigation{
    internal func move(to date: Date, animated: Bool) {
    }
    internal func deviceIsRotated() {
    }
    internal func selectedEventForAddSession(event:EventDetail) {
    }
}


protocol CalenderViewControllerDelegate : NSObjectProtocol {
    func calendarViewController(_ controller:CalendarTypeController, showDate:NSDate)
}

Hope this code will help you!

Abhijit
  • 173
  • 1
  • 7