1

我正在使用 Swift 2 和 JTAppleCalendar Cocoa Pod 在我的应用程序中构建我的日历。

我正在尝试实现configureCalendar协议中唯一的功能JTAppleCalendarViewDataSource

这是 pod 给出的函数定义:

func configureCalendar(calendar: JTAppleCalendarView) -> (startDate: NSDate, endDate: NSDate, numberOfRows: Int, calendar: NSCalendar)

这是我的实现:

extension CalendarViewController:  JTAppleCalendarViewDataSource {
    func configureCalendar(calendar: JTAppleCalendarView) -> (startDate: NSDate, endDate: NSDate, numberOfRows: Int, calendar: NSCalendar) {
        formatter.dateFormat = "yyyy MM dd"
        formatter.timeZone = NSCalendar.currentCalendar().timeZone
        formatter.locale = NSCalendar.currentCalendar().locale
        let startDate = formatter.dateFromString("2017 01 01")
        let endDate = formatter.dateFromString("2017 12 31")
        let calendar = NSCalendar.currentCalendar()
        return (startDate!, endDate!, 5, calendar)
    }    
}

我从编译器得到这个错误:

CalendarViewController.swift:32:1: Type 'CalendarViewController' does not conform to protocol 'JTAppleCalendarViewDataSource'

JTAppleCalendar.JTAppleCalendarViewDataSource:11:17: Protocol requires function 'configureCalendar' with type '(JTAppleCalendarView) -> (startDate: NSDate, endDate: NSDate, numberOfRows: Int, calendar: NSCalendar)'

为什么我不遵守协议?

4

1 回答 1

1

通过将我的 return 语句更改为如下所示来修复它:

return (startDate: startDate!, endDate: endDate!, numberOfRows: 5, calendar: calendar)
于 2017-04-23T12:45:25.357 回答