Cộng đồng Hỏi & Đáp của Inflearn
콘솔창 print 내용 안 뜸
Đã giải quyết
Viết
·
200
0
Dispatch Queue강의를 듣는도중에
앱을 실행시키고 맨 위 버튼을 누르면 숫자가 콘솔창에 출력되어야하는데 출력되지 않습니다ㅠㅠ
맨 밑에 all output이라 떠야하는데 저는 눈모양이랑 토글?모양이 나오는 점이 다른 것 같은데 어떻게 바꾸나요...
iosswift
Câu trả lời 1
0
enilv0529
Người chia sẻ kiến thức
action1매서드 내용을 다음처럼 변경해 보세요
simpleClosure {
finishLabel.text = "끝"
}







//
// ViewController.swift
// DispatchQueue
//
// Created by ohseungyeon on 8/8/24.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var timerLabel: UILabel!
@IBOutlet weak var finishLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true){
timer in
self.timerLabel.text = Date().timeIntervalSince1970.description
}
}
@IBAction func action1(_ sender: Any) {
finishLabel.text="끝"
}
func simpleClosure(completion: ()->Void){
//긴 작업이라는 것을 가정하기 위해서 스레드를 잠깐씩 멈춰보자
for index in 0..<10 {
Thread.sleep(forTimeInterval: 0.2)
print(index)
}
completion()
}
}