Re: [swift-users] Waiting for mouse input in a while loop (OS X)

2016-03-23 Thread Ergin Bilgin via swift-users
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

Re: [swift-users] Waiting for mouse input in a while loop (OS X)

2016-03-23 Thread Ramakrishna Mallireddy via swift-users
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

Re: [swift-users] Waiting for mouse input in a while loop (OS X)

2016-03-23 Thread Jean-Denis Muys via swift-users
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

Re: [swift-users] Waiting for mouse input in a while loop (OS X)

2016-03-23 Thread Ergin Bilgin via swift-users
"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

Re: [swift-users] Waiting for mouse input in a while loop (OS X)

2016-03-23 Thread George King via swift-users
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

Re: [swift-users] Waiting for mouse input in a while loop (OS X)

2016-03-23 Thread Ergin Bilgin via swift-users
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

Re: [swift-users] Waiting for mouse input in a while loop (OS X)

2016-03-23 Thread George King via swift-users
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

[swift-users] Waiting for mouse input in a while loop (OS X)

2016-03-23 Thread Ergin Bilgin via swift-users
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