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
- Refactoring
- HIG
- 클린 코드
- RxCocoa
- 애니메이션
- swift documentation
- rxswift
- 리펙터링
- clean architecture
- 리펙토링
- ios
- uiscrollview
- tableView
- uitableview
- Protocol
- swiftUI
- MVVM
- Clean Code
- collectionview
- combine
- UICollectionView
- ribs
- 리팩토링
- SWIFT
- 스위프트
- Human interface guide
- map
- Xcode
- Observable
- UITextView
Archives
- Today
- Total
김종권의 iOS 앱 개발 알아가기
[iOS - swift] 시간 정보 format (시, 분, 초) 본문
초 정보 -> 시, 분 표현
- TimeParts 구조체 정의
public struct TimeParts: CustomStringConvertible {
public var hours = 0
public var minutes = 0
public var description: String {
return NSString(format: "%02d:%02d", hours, minutes) as String
}
}
- Int를 extension하여 TimeParts 모델을 리턴하는 코드 정의
extension Int {
public func toTimeParts() -> TimeParts {
let seconds = self
let mins = (seconds % 3600) / 60
let hours = seconds / 3600
return TimeParts(hours: hours, minutes: mins)
}
}
사용
- 초 단위 ETA 정보를 가지고 String으로 반환하는 함수 정의
- R.swift프레임워크 사용 참고 : ios-development.tistory.com/306
func formattedETA() -> String {
let timeParts = self.toTimeParts()
var etaString: String
if timeParts.hours != 0 {
etaString = Strings.remainTimeFormat(timeParts.hours, timeParts.minutes) // R.swift 프레임워크 사용
} else {
let min = timeParts.minutes == 0 ? 1 : timeParts.minutes
etaString = Strings.remainTimeFormat(min)
}
return etaString
}
'iOS 응용 (swift)' 카테고리의 다른 글
[iOS - swift] 토스트 메세지 (toast message), 글자에 따른 toast view width 동적 조절, 문자열 크기 동적 계산 (0) | 2021.02.19 |
---|---|
[iOS - swift] tableView 스크롤바 표출 flashScrollIndicators() (0) | 2021.02.18 |
[iOS - swift] 위치 이동 테스트 (simulate location, .gpx) (0) | 2021.02.09 |
[iOS - swift] FloatingPanel, bottom sheet (0) | 2021.02.06 |
[iOS - swift] UITextView에 Placeholder 추가 (STTextView 프레임워크) (0) | 2021.02.03 |
Comments