2016-11-10 70 views
0

試圖將其轉換爲Swift 3.0時出現問題。無法調用非函數類型的值

我:

public func calendarView(_ view: DDCalendarView, eventsForDay date: Date) -> [Any]? { 
     let daysModifier = (date as NSDate).days(from: Date()) 
     //var daysMod = date.days(from: Date()) 

     //var newE = self.events(forDay: daysModifier as Int) as NSArray 
     var Good = self.events(forDay: daysModifier) as Any 
     var dates = [NSMutableArray]() 
     var e:DDCalendarEvent 

     for e in Good as! [AnyObject] { 

      if e.dateBegin(isEqual(date)) as! Bool == true || e.dateEnd(isEqual(date)) as! Bool == true { 
       dates.append(e as! NSMutableArray) 
      } 
    } 

     return dates 
    } 

如果e.dateBegin(的isEqual(日期)){}是給這種錯誤的情況。 而Objective-C代碼的代碼是:

- (NSArray *)calendarView:(DDCalendarView *)view eventsForDay:(NSDate *)date { 
    //should come from db ;) NOW using testdata 
    NSInteger daysMod = [date daysFromDate:[NSDate date]]; 
    NSArray *newE = [self eventsForDay:daysMod]; //always today ;) 

    NSMutableArray *dates = [NSMutableArray array]; 
    for (DDCalendarEvent *e in newE) { 
     if([e.dateBegin isEqualDay:date] || 
      [e.dateEnd isEqualDay:date]) { 
      [dates addObject:e]; 
     } 
    } 
    return dates; 
} 

和isEqualDay功能

- (BOOL)isEqualDay:(NSDate *)date { 
    NSDateComponents *compA = self.currentCalendarDateComponents; 
    NSDateComponents *compB = date.currentCalendarDateComponents; 
    return ([compA day]==[compB day] && [compA month]==[compB month ]&& [compA year]==[compB year]); 
} 

其返回bool值的任何解決方案呢?

回答

1

這條線:

if e.dateBegin(isEqual(date)) as! Bool == true || e.dateEnd(isEqual(date)) as! Bool == true { 

應該是:

if e.dateBegin.isEqualDay(date) == true || e.dateEnd.isEqualDay(date) == true { 

這是假設你已經又譯isEqualDay:方法上Date的擴展功能。

順便說一句 - 你的翻譯還有很多其他問題。以上內容僅涵蓋您在問題中詢問的特定行。

下面列出的是你想要什麼:

public func calendarView(_ view: DDCalendarView, eventsForDay date: Date) -> [Date] { 
    let daysModifier = date.days(from: Date()) // return Int 
    let newE = self.events(forDay: daysModifier) // return [DDCalendarEvent] 

    var dates = [Date]() 
    for e in newE { 
     if e.dateBegin.isEqualDay(date) == true || e.dateEnd.isEqualDay(date) == true { 
      dates.append(e) 
     } 
    } 

    return dates 
} 
+0

@rmddy讓我申請你的代碼,你suggest.will儘快回覆您.btw你是主謀。 –

+0

這個函數返回一個數組public func calendarView(_ view:DDCalendarView,eventsForDay date:Date) - > [Any] { 代替日期我需要放任何數據源方法,否則它顯示錯誤.. –

+0

好的,請隨時進行一些更改。我對你的'DDCalendarView'類一無所知。我只是試圖提供更好的翻譯。有可能會需要一些小的改變。 – rmaddy

相關問題