Skip to content

Skip Column in Encoder (and Decoder)聽#46

Description

@rmnblm

Question

Hey @dehesa 馃憢

I am fairly new to this package and I have a question.
I want to skip a column during export and import.

Export: Given a CSVEncoder and struct Pet

struct Pet {
  let name: String
  let age: Int
}
let pets = ...
let encoder = CSVEncoder { $0.headers = ["name", "age"] }
let data = try encoder.encode(pets)

Is it possible to skip a particular column, that is, encode only a single column "name" into a csv file?

Import: Given a CSVDecoder,

let decoder = CSVDecoder()
let result = try decoder.decode([Pet].self, from: data)

Can I import data into an array of Pet, if data does not contain an age column (and perhaps give it a default value if the column does not exist)?

Many thanks for your help! 馃槉
Roman

System

  • OS: macOS Monterey
  • CodableCSV: 0.6.7

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions