我正在使用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)'
为什么我不遵守协议?
答案 0 :(得分:1)
通过将我的return语句更改为如下来修复它:
return (startDate: startDate!, endDate: endDate!, numberOfRows: 5, calendar: calendar)