I’m doing something rather simple, but the execution doesn’t stop at the “wait”, it just continues so the data is incorrect. In the output I see the “After wait” message before the “Read the power….” message, and when the method returns it has the initialization value instead of the correct one. Can you tell me what I’m missing?
dispatchGroup.enter()
characteristic.readValue(completionHandler:
{ (error) in
if error != nil
{
print(error!.localizedDescription)
}
else
{
powerState = characteristic.value as! Int
print("CLightBulb: -->Read the power state. It is \(powerState) at " + Date().description(with: Locale.current))
}
})
dispatchGroup.leave()
dispatchGroup.wait()
print("CLightBulb: (After wait) The power value is \(powerState) at " + Date().description(with: Locale.current))