0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

BrightFuturesのレスポンス結果を表示するのはonSuccessのスコープ内でやろう

Last updated at Posted at 2019-09-27

BrightFuturesを使用した非同期処理の場合、
APIから取得した結果を表示するためにUILable等に設定するのは、onSuccessのスコープ内でやること。
そうしないと非同期処理のため、値がまだ帰ってきていない内に描画処理が走り、想定通りに反映されない。

普段JavaScriptで書いてるときは自然としてそうだが失念してた。
Async/Awaitほしい、、


class SomeViewController: AutoLayoutViewController {

  private var someObj:SomeObject = SomeObject()
  private var someLabel: UILabel

   override func viewDidLoad() {

   [BrightFuturesを使った非同期処理]
     .onSuccess { success in
       someObj = success
       
       // ここが正解
       self.someLabel.text = success.text
     }

   // ここでやると反映されない
   // self.someLabel.text = success.text

  }

}

0
0
0

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?