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 |
Tags
- SWIFT
- ribs
- Xcode
- RxCocoa
- Refactoring
- 리팩토링
- map
- 리펙터링
- UICollectionView
- ios
- tableView
- 리펙토링
- combine
- swift documentation
- uiscrollview
- uitableview
- Human interface guide
- collectionview
- HIG
- Protocol
- MVVM
- Clean Code
- UITextView
- rxswift
- clean architecture
- swiftUI
- 클린 코드
- 스위프트
- 애니메이션
- Observable
Archives
- Today
- Total
김종권의 iOS 앱 개발 알아가기
[iOS - swift] private(set) 외부에서 읽기만 가능하고, 내부에서는 쓰기가 가능하도록 하는 간결한 코드 (getter, setter) 본문
iOS 기본 (swift)
[iOS - swift] private(set) 외부에서 읽기만 가능하고, 내부에서는 쓰기가 가능하도록 하는 간결한 코드 (getter, setter)
jake-kim 2021. 9. 6. 22:48스위프트의 private(set) 키워드
- private(set)을 쓰지 않고 외부에서 읽기만 가능하고 내부에서만 수정이 가능하도록 하는 코드
public class Data {
private var _id: String
public var id: String {
get {
return _id
}
set {
return _id = id
}
}
}
- private(set) 사용
public class Person {
internal private(set) var id: String
}
- internal은 생략해도 무방
- 읽기는 internal, 쓰기는 private으로 접근 제한이 정의된 프로퍼티 id
public class Person {
private(set) var id: String
}
'iOS 기본 (swift)' 카테고리의 다른 글
Comments