티스토리 뷰
반응형
Swift DispatchSourceTimer에 대해 알아보겠습니다.
GCD(Grand Central Dispatch)
- 작업을 병렬적으로 처리하기 위해 애플에서 제공하는 API
- 스레드를 만들거나 관리하기 어려운 일들을 맡아준다.
DispatchSourceTimer
Apple Developer Documentation
developer.apple.com
var timer: DispatchSourceTimer?
func startTimer() {
if self.timer == nil {
self.timer = DispatchSource.makeTimerSource(flags: [], queue: .main)
self.timer?.schedule(deadline: .now(), repeating: 1)
self.timer?.setEventHandler(handler: { [weak self] in
guard let self = self else { return }
})
}
- 타이머 인스턴스를 생성
self.timer = DispatchSource.makeTimerSource(flags: [], queue: .main)
- 어떤 주기로 타이머를 실행할건지 설정
self.timer?.schedule(deadline: .now(), repeating: 1)
- 타이머와 함께 연동될 EventHandler를 할당
self.timer?.setEventHandler(handler: { [weak self] in
guard let self = self else { return }
})
반응형
'Swift' 카테고리의 다른 글
OpenWeather API 사용하는 법 (0) | 2022.02.17 |
---|---|
Swift URLSession (0) | 2022.02.16 |
Swift DatePicker 사용해보기 (0) | 2022.02.03 |
Swift UICollectionView 알아보기 (0) | 2022.02.02 |
Swift UITabBarController 알아보기 (0) | 2022.02.01 |
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- swipe
- LazyHStack
- SwiftLint
- NavigationLink
- Swift
- UIScrollView
- Android
- 문자열
- subscript
- dictionary
- 웹뷰
- Alamofire
- string
- Realtime Database
- Observable
- 라이트모드
- Java
- RxSwift
- Apple
- ios
- SwiftUI
- 다크모드
- UIButton
- UITabBarController
- WebView
- autolayout
- remote config
- gcd
- Firebase
- github
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
글 보관함