我正在使用FSCalender库制作日程表应用。
在事件数函数下(如果返回int则产生一个点),我正在从Firebase数据库中获取数据,并尝试在数据库中存储日期的情况下显示该点。
但是,返回int后,会发生错误:
void函数中意外的非void返回值
由于有这个第三方库,我真的陷于修复此错误的过程中。 有解决这个问题的想法吗?提前致谢。
//function for making dot: we want to make dots after selecting and saving time
func calendar(_ calendar: FSCalendar, numberOfEventsFor date: Date) -> Int {
// fetching from firebase db. if there is a date stored on the date, a dot will be shown
let tmpDate = Calendar(identifier: .gregorian)
let year = tmpDate.component(.year, from: date)
let month = tmpDate.component(.month, from: date)
let day = tmpDate.component(.day, from: date)
let m = String(format: "%02d", month)
let d = String(format: "%02d", day)
let da = "\(year)/\(m)/\(d)"
if let uid = Auth.auth().currentUser?.uid {
let ref = Database.database().reference().child("schedule").child(uid)
ref.observe(.childAdded, with: { (snapshot) in
//print(snapshot.value)
guard let dictionary = snapshot.value as? [String: Any] else {return}
Database.fetchUserWithUID(uid: uid, completion: { (user) in
let schedule = Schedule(user: user, dictionary: dictionary)
if schedule.date == da {
print("a dot will show")
return 1 //Error "Unexpected non-void return value in void function" occurs here
}
})
}) { (err) in
print("failed to fetch data")
}
}
return 0
}