Implemented the StringAdapter and the DateAdapter adapters for the Profile module.

This commit is contained in:
Javier Cicchelli 2022-12-12 02:48:36 +01:00
parent 71871c6ae0
commit d7ec5aad47
3 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,41 @@
//
// DateAdapter.swift
// Profile
//
// Created by Javier Cicchelli on 12/12/2022.
// Copyright © 2022 Röck+Cöde. All rights reserved.
//
import Foundation
struct DateAdapter {
// MARK: Properties
private let dateFormatter: DateFormatter = .dateTimeFormatter
// MARK: Functions
func callAsFunction(value: Date?) -> String {
if let value {
return dateFormatter.string(from: value)
} else {
return .Constants.noValue
}
}
}
// MARK: - DateFormatter+Formats
private extension DateFormatter {
static let dateTimeFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .long
formatter.timeStyle = .short
formatter.locale = .current
return formatter
}()
}

View File

@ -0,0 +1,13 @@
//
// StringAdapter.swift
// Profile
//
// Created by Javier Cicchelli on 12/12/2022.
// Copyright © 2022 Röck+Cöde. All rights reserved.
//
struct StringAdapter {
func callAsFunction(value: String?) -> String {
value ?? .Constants.noValue
}
}

View File

@ -0,0 +1,13 @@
//
// String+Constants.swift
// Profile
//
// Created by Javier Cicchelli on 12/12/2022.
// Copyright © 2022 Röck+Cöde. All rights reserved.
//
extension String {
enum Constants {
static let noValue = "-"
}
}