Swiftpack.co - elegantchaos/CSVCoding as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by elegantchaos.
elegantchaos/CSVCoding v2.0.0
CSV Coding support for Swift
⭐️ 2
🕓 1 year ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/elegantchaos/CSVCoding.git", from: "v2.0.0")

CSVEncoder

Very basic support for encoding an Swift object as CSV.

Usage

let encoder = CSVEncoder()
encoder.dateEncodingStragegy = .iso8601
let data = try! encoder.encode(rows: [MyCodableThing()])

You pass the encoder a list of codable objects.

This results in a data object which is a UTF-8 string.

Each line of the string contains a value for each property of the codable object.

Headers

By default the first line of the encoded text is a header, using the names of the properties.

This can be disabled with encoder.headerEncodingStrategy = .none, or you can supply header names to the encoder manually when you create it.

You can also supply some translation settings with an optional bundle, table and/or prefix. If these are supplied, the header names are used as NSLocalizedString keys, and the resulting translated versions are written out.

Decoding

Currently only encoding is supported. Simple decoding should be quite easy for me to add however, so please open an issue if you need it.

GitHub

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

Release Notes

2.0
1 year ago

Cleaned up header translation. Made the use of header/heading more consistent, resulting in a very slight API change.

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