LoginSignup
7
9

More than 5 years have passed since last update.

NSThreadで処理を止めると、NSConnectionも止まる

Posted at

スクリプト言語ばかり触っていたので気づかなかったのですが、NSThreadを使うときの注意をまとめます。

もはやタイトルどおりなのですが、NSThreadを使うとメインのスレッド処理を止めてしまいます。

そこで通信などをメインスレッドで行っているときの処理を待たせる場合は、

[NSThread sleepForTimeInterval:3];

ではなく、

[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];

で処理を止めると、通信を滞り無く進めつつ、処理待ちができます。

7
9
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
9