thiesdiggity thiesdiggity - 8 months ago 40
Swift Question

Objective-C console app that will never terminate while connected to Redis

I have a Objective-C/Swift console application that I am updating to connect to Redis (pub/sub). However, the application exits prior to even connecting to the Redis server.

How can I have the application (main thread) essentially run forever without blocking the background threads (NSOperationQueue)?

I've developed something similar in C# and used the "Console.Read()" function to essentially wait forever. I tried using the same approach for this program with "scanf(...)" but that appears to block the execution of the background threads.

I found this question, Console App Terminating Before async Call Completion for C#. Is there anything similar in Objective-c/Swift?

Any input would be greatly appreciated.


 [[NSRunLoop currentRunLoop] run];

Do that on your main thread. It'll never return.

If you have some code you want to invoke in the context of the run loop, use dispatch_after() or performAfter:... or variant therein.