반응형
스위프트 날짜 구하는 예제를 다뤄보도록 하겠습니당.
//날짜 포맷 (클로저 사용)
let formatDate:DateFormatter = {
let f = DateFormatter()
//날짜는 long 스타일로 출력
f.dateStyle = .long
//시간은 short 스타일로 출력
f.timeStyle = .short
// 한글로 변경
f.locale = Locale(identifier: "Ko_kr")
return f
}()
// 날짜 삽입 (여기서는 테이블 뷰)
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
let target = DataManager.shared.memoList[indexPath.row]
cell.textLabel?.text = target.content
//문자열로 리턴 해줌.
cell.detailTextLabel?.text = formatDate.string(for: target.insertDate)
return cell
}
결과 :
반응형
'개발언어 > Swift' 카테고리의 다른 글
스위프트 화면 전환 옵션 (show, showDetail, present Modally 등) (0) | 2022.01.14 |
---|---|
스위프트 view 종류 및 설명 (0) | 2022.01.13 |
스위프트 테이블 뷰(table view, dataSource, delegate)이란? (0) | 2022.01.13 |
스위프트 네비게이션 컨트롤러(navigation controller) (0) | 2022.01.11 |
스위프트 메모장 코드 뜯기 (appdelegate, plist, scenedelegate 역할) (0) | 2022.01.07 |