0

I'm making a schedule app using FSCalender library.

Under the numberofevents func (for making an dot if returns an int), I'm fetching a data from Firebase database and trying show the dot if there's a date stored in the database.

However, after returning int, the error occurs:

Unexpected non-void return value in void function

Because of this third-party library, I really got stuck at fixing this error. Any ideas to solve this problem? Thanks in advance.

//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
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
akaakoz
  • 248
  • 6
  • 16
  • 1
    The `observe` closure you provide does not expect a `return` statement. I think you want to return the int value from the `calendar` func, but Firebase works asynchronically, therefore you should first make sure you understand how Firebase observers work, and how to incorporate the result into your view controller. – Andreas Oetjen Oct 16 '18 at 08:29
  • @AndreasOetjen Thanks. I'll look into it! – akaakoz Oct 16 '18 at 13:07

0 Answers0