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
- Clean Code
- uiscrollview
- scrollview
- swiftUI
- tableView
- Refactoring
- clean architecture
- swift documentation
- SWIFT
- UITextView
- 클린 코드
- Xcode
- 리팩토링
- 애니메이션
- 스위프트
- UICollectionView
- 리펙토링
- ios
- collectionview
- Protocol
- rxswift
- uitableview
- combine
- map
- Observable
- HIG
- ribs
- MVVM
- Human interface guide
- RxCocoa
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
jake-kim님의
글이 좋았다면 응원을 보내주세요!