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
- map
- UICollectionView
- Clean Code
- Xcode
- HIG
- Observable
- 리팩토링
- ribs
- collectionview
- 클린 코드
- RxCocoa
- rxswift
- Protocol
- scrollview
- uiscrollview
- combine
- Human interface guide
- swiftUI
- MVVM
- SWIFT
- 애니메이션
- 리펙토링
- swift documentation
- Refactoring
- ios
- tableView
- 스위프트
- clean architecture
- uitableview
- UITextView
Archives
- Today
- Total
김종권의 iOS 앱 개발 알아가기
[iOS - swift] Singleton사용 방법 본문
Singleton사용방법
- static let으로 자기 자신을 선언
- private init() {}코드가 없다면, static let을 사용할 때마다 객체가 매번 생성되므로 private init선언
class Singleton {
static let shared = Singleton()
private init() {}
}
- 전역변수를 사용하여 인스턴스를 사용하게 되면,
- 사용 시점에 초기화가 되는 장점
- GCD의 dispatch_once도 자동 적용되어 인스턴스 생성 (thread safe)
'iOS 기본 (swift)' 카테고리의 다른 글
| [iOS - swift] textField델리게이트 함수 shouldChangeCharactersIn, range, NSRange (0) | 2020.11.08 |
|---|---|
| [iOS - swift] PresentedViewController vs PresentingViewController (0) | 2020.11.08 |
| [iOS - swift] for - in - where 문법 (0) | 2020.11.07 |
| [iOS - swift] ViewController의 presentation style / Transition Style (6) | 2020.11.01 |
| [iOS - swift] Scale To Fill / Aspect Fit / Aspect Fill (2) | 2020.11.01 |
Comments
