[swift-users] Waiting for mouse input in a while loop (OS X)
George King
gwk.lists at gmail.com
Wed Mar 23 11:52:51 CDT 2016
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 NSResponder (or UIResponder on iOS), e.g. your root NSView or your NSViewController. Then override `func mouseDown(event: NSEvent)` and increment the counter there.
Hope that helps,
George
>
> On Mar 23, 2016, at 12:35 PM, Ergin Bilgin via swift-users <swift-users at swift.org> wrote:
>
> 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 Kit if you can think a solution related to it.
>
> Cheers,
>
> Ergin
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
More information about the swift-users
mailing list