CVCalendar和Firestore如何创建同步功能

时间:2018-08-22 22:22:54

标签: swift xcode firebase synchronization google-cloud-firestore

我当前的问题是我的函数 dotMarker 将在函数 dateExists 之前返回值 shouldShow 。 > 可以从Firestore查询返回值。这导致所有 shouldShow 的值均为false,并且不会更改。

extension CVCalendarViewController: CVCalendarMenuViewDelegate, 
CVCalendarViewDelegate, CVCalendarViewAppearanceDelegate {

/// Required method to implement!
func firstWeekday() -> Weekday {
    return .sunday
}

func dotMarker(shouldShowOnDayView dayView: DayView) -> Bool {
    let group = DispatchGroup()
    var shouldShow:Bool? = false
    dateExists(for: dayView.date.convertedDate()) {result in
        group.enter()
        shouldShow = result
        group.leave()
    }
    group.wait()
    return shouldShow!
}

fileprivate func dateExists(for date: Date?, completionHandler:@escaping (Bool) -> Void) {
    DispatchQueue.global().async(execute: {
        DispatchQueue.main.sync{
            //var Variable:Bool = false
            let dateAtBeginning = date?.firstSecondInDay()
            let dateAtEnd = date?.lastSecondInDay()
            let btRef = self.db.collection("bomtracking")
            //print(dateAtBeginning)
            //print(dateAtEnd)
            let query = btRef
                .whereField("UID", isEqualTo: self.UID)
                .whereField("timestamp", isGreaterThan: dateAtBeginning)
                .whereField("timestamp", isLessThan: dateAtEnd)

            query.getDocuments(){ (querySnapshot, err) in
                if let err = err {
                    print("Error getting documents: \(err))")
                }
                else {
                    if (querySnapshot?.count)! > 0 {
                        //print("more than one")
                        print(querySnapshot?.count)
                        completionHandler(true)
                    }
                    else {
                        completionHandler(false)
                    }
                }
            }
        }
    })
}

func dotMarker(colorOnDayView dayView: DayView) -> [UIColor] {
    let Color = UIColor.blue
    return [Color]
}
}

我的目标是做什么:我希望日历显示该日期在查询中找到的所有日期的点。

如果有人可以帮助我弄清楚我需要采取什么方向来帮助解决此问题,或者为我解决该问题并给我建议和指导,我们将不胜感激!

0 个答案:

没有答案