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 |
Tags
- UITextView
- RxCocoa
- Observable
- ios
- 리팩토링
- swiftUI
- 스위프트
- tableView
- 리펙터링
- uitableview
- MVVM
- Xcode
- ribs
- swift documentation
- Protocol
- UICollectionView
- Human interface guide
- clean architecture
- uiscrollview
- rxswift
- combine
- Refactoring
- 클린 코드
- 리펙토링
- HIG
- 애니메이션
- SWIFT
- map
- collectionview
- Clean Code
Archives
- Today
- Total
김종권의 iOS 앱 개발 알아가기
[iOS - swift] Type casting 표현식 본문
Type casting 일반적인 표현
String -> Double
- 가장 일반적인 방법
- Double에 문자열을 집어넣는 방법
Double("1")
- 또는 extension String에 넣는 방법
extension String {
var asDouble: Double? {
Double(self)
}
}
"1".asDouble
Type casting 표현식
- 표현식을 정의해놓는 방법
let stringToDouble = Double.init as (String) -> Double?
- 동작
- 1) 인수가 (String)으로 삽입
- 2) 인수가 Double.init에 들어감 - Double(인수)형태로 초기화
- 3) 그 값을 리턴
print(stringToDouble("a")) // Optiona(nil)
print(stringToDouble("1")) // Optional(1)
* 참고
https://github.com/apple/swift-evolution/blob/main/proposals/0315-placeholder-types.md
'iOS 응용 (swift)' 카테고리의 다른 글
[iOS - swift] layoutIfNeeded() 동작원리 이해하기 (1) | 2024.02.08 |
---|---|
[iOS - swift] Autolayout과 translatesAutoresizingMaskIntoConstraints 이해하기 (Autoresizing Mask) (1) | 2024.02.07 |
[iOS - swift] Optional Operator (옵셔널 프로퍼티 연산) (0) | 2024.02.05 |
[iOS - swift] any vs some 키워드 (dynamic dispatch, static dispatch, type erase) (1) | 2024.02.02 |
[iOS - swift] 3. 추상화 - 프로토콜에 제네릭스 사용하는 추상화 이해하기 (1) | 2024.02.01 |
Comments