0

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.

Thanks!

Community
  • 1
  • 1
thiesdiggity
  • 1,897
  • 2
  • 18
  • 27

1 Answers1

0
 [[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.

bbum
  • 162,346
  • 23
  • 271
  • 359