Swift 連線更新資料成功,但是有時有顯示出來,有時候失敗?

資料還沒傳完就切換畫面,導致show不出更新資料

APP常常需要更新資料,不管是Real-time還是隔一段時間,會遇到

資料還沒傳完就切換畫面,導致show不出更新資料

這時候你需要 轉圈圈出來幫你一下。

呼叫API的方法需要在副執行緒(DispatchQueue(label: “”).async {})執行,在主執行緒(DispatchQueue.main.async{})做就會停住給你看XD。

在這邊使用的方法是

DispatchQueue.main.async{

present (呼叫)跑圈圈的ViewController

}

DispatchQueue(label: “”).async {

建立連線

儲存資料.etc

DispatchQueue.main.async{

Dismiss (消失)跑圈圈的ViewController

}

}

這邊可以看到是可以在副執行緒還可以使用主執行緒喔!

--

--

Major in physical education. Football referee. And high interest in looking the world through the numbers.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mario tsai

Major in physical education. Football referee. And high interest in looking the world through the numbers.