신속한 비동기 작업에 많은 혼란을 겪었습니다.swift : async task + completion
func buttonPressed(button: UIButton) {
let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
dispatch_async(queue) {() -> Void in
// display the animation of "updating"
// do the math here
dispatch_async(dispatch_get_main_queue(), {
// update the UI
}
}
}
그러나, 나는 UI가 완료 될 내 계산을 기다리지 않고 업데이트되는 것을 발견 :
func buttonPressed(button: UIButton) {
// display an "animation" tell the user that it is calculating (do not want to freeze the screen
// do some calculations (take very long time) at the background
// the calculations result are needed to update the UI
}
내가 이런 일을하려고 노력 ... 이런 식으로 뭔가 할 원하는 것입니다 . 나는 비동기 큐의 사용에 대해 혼란 스럽다. 누구 한테 도움이 되니? 감사.
인 UI를 갱신하는 배경 스레드에 다시 메인 스레드 종료 후의 계산 함수의 끝에
'// 여기에 수학을 써서 서버에 요청을합니까? – bbarnhart
아니요, 꽤 오랜 시간이 걸리므로 화면을 정지시키고 싶지는 않습니다. ( – user6539552