반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- LazyHStack
- 웹뷰
- 다크모드
- RxSwift
- WebView
- 라이트모드
- Observable
- SwiftLint
- gcd
- Swift
- Firebase
- remote config
- SwiftUI
- github
- autolayout
- subscript
- Java
- ios
- string
- UITabBarController
- Alamofire
- Apple
- dictionary
- 문자열
- UIScrollView
- Android
- NavigationLink
- Realtime Database
- UIButton
- swipe
Archives
- Today
- Total
점진적 과부하 개발 블로그
Swift DispatchSourceTimer 본문
반응형
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 |