훌이
후리스콜링개발
훌이

블로그 메뉴

  • 왈 (iOS APP)
  • Github
전체 방문자
오늘
어제
  • 전체 (171)
    • ⭐️ 개발 (140)
      • JAVA (4)
      • Web (5)
      • iOS & Swift (94)
      • iOS Concurrency (4)
      • Rx (18)
      • Git (6)
      • WWDC (1)
      • Code Refactor (3)
      • Server (1)
    • ⭐️ Computer Science (22)
      • 운영체제 (10)
      • 네트워크 (5)
      • PS (7)
    • 경제시사상식 (8)
    • 기타 등등 (0)

인기 글

최근 글

05-29 00:58

티스토리

hELLO · Designed By 정상우.
훌이

후리스콜링개발

[iOS] Formatted API in iOS15
⭐️ 개발/iOS & Swift

[iOS] Formatted API in iOS15

2022. 7. 13. 16:16
728x90
반응형


iOS15부터 나온 Formatted API
숫자, 날짜, 시간 등과 같은 데이터를 사용자가 원하는 현지화된 문자열로 변환해준다.
사용자의 디바이스의 위치와 언어설정에 따라 다르게 나올 수 있다.

//: [Previous](@previous)

import UIKit


let value = Date()

print(value) // 2022-07-13 07:10:50 +0000
print(value.formatted()) // PM/AM으로 정리되어서 나옴
print(value.formatted(date: .omitted, time: .shortened)) // 시간만 나옴
print(value.formatted(date: .complete, time: .shortened)) // 전체날짜가 영어로 나옴
print(value.formatted(date: .abbreviated, time: .shortened)) // July 대신 Jul
print(value.formatted(date: .long, time: .standard)) // 초까지 나옴
print(value.formatted(date: .numeric, time: .omitted)) // 7/13/2022

let locale = Locale(identifier: "ko-KR")

let result = value.formatted(.dateTime.locale(locale).day().month(.twoDigits).year())
print(result) // 한국식으로 나옴

let result2 = value.formatted(.dateTime.day().month(.twoDigits).year())
print(result2) // 기존 영어권으로 나옴


// Number String

print(50.formatted(.percent)) // %가 붙음
print(234234534.formatted()) // 3개씩 콤마 찍혀서 나옴
print(78652.formatted(.currency(code: "krw"))) // 우리나라 화폐단위로 나옴

let result3 = ["올라프", "엘사", "안나"].formatted()
print(result3) // 영어 and를 앞에서 두 번째에 자동 추가
//: [Next](@next)

 

728x90
반응형
저작자표시 비영리 변경금지 (새창열림)

'⭐️ 개발 > iOS & Swift' 카테고리의 다른 글

[iOS] Enum으로 코드 리팩토링  (0) 2022.07.19
[iOS] for - in / forEach 동작구조?  (0) 2022.07.19
[iOS] Copy items if needed, Move to Trash  (0) 2022.07.13
[iOS] Rendering Mode, Build Phases, NavigationController, TabBarController  (0) 2022.07.11
[iOS] 1주차에 새롭게 알게 된 것들  (0) 2022.07.10
    '⭐️ 개발/iOS & Swift' 카테고리의 다른 글
    • [iOS] Enum으로 코드 리팩토링
    • [iOS] for - in / forEach 동작구조?
    • [iOS] Copy items if needed, Move to Trash
    • [iOS] Rendering Mode, Build Phases, NavigationController, TabBarController
    훌이
    훌이

    티스토리툴바