Swiftpack.co - bartleby/DateFormatterPool as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by bartleby.
bartleby/DateFormatterPool 1.0.1
Date Formatter Pool - is a small utility that creates and stores your Date Formatter for simpler reuse
⭐️ 16
🕓 1 year ago
.package(url: "https://github.com/bartleby/DateFormatterPool.git", from: "1.0.1")

Date Formatter Pool

Date Formatter Pool - is a small utility that creates and stores your Date Formatter for simpler reuse

Installation

is available in the Swift Package Manager.

Swift Package Manager

https://github.com/bartleby/DateFormatterPool.git

Basic Usage

First, add a your format to a Pool, through the expansion of DateFormat

extension DateFormat {
    static let shortDateAndTime = DateFormat(value: "MMM d, E 'at' HH:mm")
    static let shortDay = DateFormat(value: "d")
    static let shortMonth = DateFormat(value: "MMM")
    static let monthAndYear = DateFormat(value: "LLLL YYYY")
    static let shortWeekName = DateFormat(value: "EE")
}

On this site you can create the format you need: nsdateformatter.com

Then get an DateFormatter from the pool using PropertyWrapper.

struct ContentView: View {
    @DateFormatterPool(.shortDateAndTime) var shortDateAndTimeFormatter
    
    var body: some View {
        VStack {
            Text(shortDateAndTimeFormatter.string(from: Date())) // Aug 23, Tue at 12:10
        }
    }
}

or in ViewModel

final class ViewModel {
    @Published var dateString: String
    
    @DateFormatterPool(.shortDateAndTime) var shortDateAndTimeFormatter
    
    //...
    
    func configure() {
        dateString = shortDateAndTimeFormatter.string(from: Date())) // Aug 23, Tue at 12:10
    }
}

Example Apps

Coming soon

License

MIT license. See the LICENSE file for details.

GitHub

link
Stars: 16
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics