How to synchronize delegates from external framework?

Hello,

From an external framework, it exposes delegates such as


gameDidMovePiece

gameDidReplacePiece

gameDidTransformPiece


I have my own function that needs information from two of these delagates. These delegates are not synchronized, the data becomes available randomly.


How do I synchronize these external delegates so in my function action is carried out when all delegates have finished?


I'm using swift 4.2, Xcode 10.2


Thanks

How do I synchronize these external delegates so in my function action is carried out when all delegates have finished?

It’s hard to say without more context. I can see there ways you might approach this:

  • If this sequence of events is always terminated by some sort of ‘end’ event, you could key off that.

  • If not, you could modify the code generating the events to generate such an ‘end’ event.

  • You could use a timer to implement a timeout, so you consider the sequence ended if you haven’t received an event within a certain time.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hello Eskimo,


Thanks for the help.


I do not have access to the framework internals to add an event. I can add an event inside the delegate methods, I will look further into this.


With regards to the timer implementation, would this be in conjunction with a Notification? Or were you thinking about using NSLock?


Again thanks for thelp.

Accepted Answer

With regards to the timer implementation, would this be in conjunction with a Notification? Or were you thinking about using

NSLock
?

Ah, um, neither. I’d use an

Timer
for this. Start the timer when you get the first event. If you get another event while the timer is still running, cancel the timer and schedule a new one for later. If the timer fires, you process the events you’ve received so far.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
How to synchronize delegates from external framework?
 
 
Q