반응형
타이머 코드를 Stack Overflow에 복붙해서 코드 진행중
Button을 눌렀을 때 초가 빠르게 줄어드는 것을 디버그창에서 볼 수 있다.
해결법.
1. Timer를 수행하는 메서드를 변수화
2. 버튼을 눌렀을 때 초기화(이미 진행 되고 있는 Timer 무효화)
var timer = Timer()
@IBAction func HardnessSelected(_ sender: UIButton) {
timer.invalidate()
timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updateCounter), userInfo: nil, repeats: true)
}
반응형
'iOS > Swift 오류 찾아 삼만시간' 카테고리의 다른 글
[Swift] Realm data migration (0) | 2022.10.19 |
---|---|
[Xcode] 터미널에서 podfile 설치 후 workspace생성 안되는 오류 (0) | 2022.08.31 |
[Xcode]Simulator에 사진 넣기 오류 (import error) / PHPPhotosErrorDomain error -1. (0) | 2022.04.28 |
[Swift] color literal / image literal error(Xcode13 이후 변경) (0) | 2022.04.08 |
[IOS] Firebase cocoapods install error(M1) (0) | 2022.04.02 |