Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/elegantchaos/csvcoding
CSV Coding support for Swift
https://github.com/elegantchaos/csvcoding
csv encoding swift
Last synced: about 1 month ago
JSON representation
CSV Coding support for Swift
- Host: GitHub
- URL: https://github.com/elegantchaos/csvcoding
- Owner: elegantchaos
- License: mit
- Created: 2021-10-04T12:59:49.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-02T15:48:12.000Z (over 2 years ago)
- Last Synced: 2024-03-15T08:48:15.618Z (10 months ago)
- Topics: csv, encoding, swift
- Language: Swift
- Homepage:
- Size: 17.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# CSVEncoder
Very basic support for encoding an Swift object as CSV.
## Usage
```swift
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.