I currently have a function that gathers a time from a database and returns it for other functions to use. It needs a parameter, which is stored in another part of the app, in order to gather the value from the database.
My problem comes when I want to call this function within an IBAction function.
Here is my code for the function:
func getDBValue(place: GMSPlace) -> Int {
var expectedValue = 0
databaseRef.child("values").child(place.placeID).observe(.value, with: { (snapshot) in
let currentValue = snapshot.value as? [Int]
if currentValue == nil {
self.noValue()
expectedValue = 0
} else {
let sumValue = currentValue?.reduce(0, +)
let avgValue = sumValue! / (currentValue?.count)!
print("The current value is \(String(describing: avgValue))")
expectedValue = avgValue
self.valueLabel.text = String(describing: avgValue)
}
})
print("This is the expected WT: \(expectedWaitTime)")
return expectedValue
}
And here is my code for my IBAction function that is having issues with multiple parameters:
@IBAction func addValuePressed(_ sender: Any, place: GMSPlace) {
print("This is the place ID: \(place.placeID)")
var expectedValue = getDBValue(place: place)
expectedValue = expectedValue + 1
print("The expectedValue is now: \(expectedValue)")
self.valueLabel.text = String(describing: expectedValue)
}
This gives me a libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
error. After some testing, it seems that the error is caused by the added parameter place: GMSPlace
in my IBAction function. Any thoughts on how to fix this?