且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

NSNotificationCenter-在不阻塞主线程的情况下等待通知发布的方式?

更新时间:2022-04-07 22:09:34

基本上我想知道在上面指定的区域中需要什么样的代码,以确保该函数一直等到提取完成?

Basically I'm wondering what sort of code I need in the above specified area to ensure that the function waits until the fetch has been completed ?

您不需要没有代码.开始提取后,请勿在方法中放入任何内容,否则将不会发生任何事情.您的程序将等待"(实际上将在处理其他输入),直到收到通知为止.

You need no code. Don't put anything in the method after you start the fetch, and nothing will happen. Your program will "wait" (it will actually be processing other input) until the notification is recieved.

在通知处理程序方法中,放入提取完成后所需执行的所有操作.这是通知和其他回调方案的要点之一-您的对象在收到需要采取行动的通知之前不会做任何进一步的事情.

In the notification handler method, put all the stuff that you need to do when the fetch is completed. This is (one of) the point(s) of notifications and other callback schemes -- your object won't do anything further until it gets the notification that it's time to act.

有没有办法在不阻塞主线程的情况下等待通知的发布?

Is there a way to wait for a notification to be posted without blocking the main thread?

这就是它的工作原理.