Thank you. I knew it should be possible with GCD, but I was just not
familiar with semaphores. Now everything perfectly works in the way I want.
Ergin
On 23 March 2016 at 20:11, Jean-Denis Muys wrote:
> Here is an outline on how you might achieve that.
>
> 1- Create a background GCD queue and
Make the loop into a function.
call the function everytime a mouseevent happened with appropriate input
counters.
var i = 1
var innerloopCounter = 1
var innerloopRunning = false
// this is the os mouseevent handler
func mouseevent(event:Event) {
if i < toSort.count {
sort(toSort)
}
}
// ++, -- ope
Here is an outline on how you might achieve that.
1- Create a background GCD queue and a GCD semaphore.
2- dispatch_async your sort routine on that queue
3- add a call to dispatch_semaphore_wait before starting your sort. This will
grab the semaphore.
4- at the //wait here point, call dispatch_se
"print(toSort)" is only a placeholder there. Yes, it will be a
visualization. I am thinking of saving each state of "toSort" to another
array and show a fake visualization after sorting is finished. Using stdin
also might be a good solution but not very presentable.
Ergin
On 23 March 2016 at 19:5
I don't know of an easy way to block the main thread and wait for GUI input,
without disrupting Cocoa. If you do not need the GUI, then I suggest using the
debugger to set a breakpoint; in general it's worth the effort to learn to use
the debugger, rather than just print statements. Alternativel
Thank you for help. Maybe I have over simplified my problem. In my first
example, your advice was totally fine. But when I want to do something more
complex, I could not figure out how to use it. For example, I want to print
each step in my insertion sort. Like this:
for i in 1.. 0) && (toSort[j-1
Hi Ergin,
Are you familiar with how events are delivered via the application runloop?
Essentially, you should not create a top-level loop that waits for input; the
application runloop does this for you. If you want to accumulate 50 clicks,
create the counter variable in the appropriate NSRespond
Hello,
I have a very simple while loop and I want to wait for a mouse click(can be
a different input, not important) between every step. What I want to
achieve is something like this:
while (i < 50){
print(i)
i += 1
waitForMouseClick() //Wait here for user input.}
I also use Sprite