私は現在、データベースから時刻を収集し、それを使用して他の関数が使用するための関数を返します。それは、データベースから値を収集するために、アプリケーションの別の部分に格納されているパラメータが必要です。IBAction関数の複数のパラメータ
私の問題は、IBAction関数内でこの関数を呼びたいときです。ここで
は、機能のために私のコードです:
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
}
そしてここでは、複数のパラメータの問題を持っている私のIBAction機能のために私のコードです:
@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)
}
これは私にlibc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
エラーになります。いくつかのテストの後、そのエラーは、IBAction関数で追加されたパラメータplace: GMSPlace
によって引き起こされたようです。どのようにこれを修正するための任意の考え?
IBActionにパラメータを追加することはできません。期間。あなたのニーズに応じて、(1)送信者が呼び出されたことを示すタグプロパティ( 'Int')を使用するか、または(2)IBAction内で' GMSPlace'インスタンスを利用可能にすることです。 – dfd