Classes

The following classes are available globally.

  • Encodes Swift types to CSV data.

    This exampls shows how multiple instances of a Person type will be encoded to CSV data. Person conforms to Codable, so it is compatible with both the CSVEndocder and CSVDecoder.

    struct Person: Codable {
       let firstName: String,
       let lastName: String,
       let age: Int
    }
    
    let people = [
        Person(firstName: "Grace", lastName: "Hopper", age: 113),
        Person(firstName: "Linus", lastName: "Torvold", age: 50)
    ]
    
    let data = try CSVEncoder().sync.encode(people)
    print(String(decoding: data, as: UTF8.self))
    
    /* Prints:
     "firstName","lastName","age"
     "Grace","Hopper","113"
     "Linus","Torvold","50"
    */
    
    See more

    Declaration

    Swift

    public final class CSVEncoder
  • The encoder for encoding multiple objects at once into a single CSV document.

    You can get an instance of the CSVSyncEncoder with the CSVEncoder.sync property.

    See more

    Declaration

    Swift

    public final class CSVSyncEncoder
  • An encoder for encoding multiple objects separately into a single CSV document.

    You can get an instance of the CSVAsyncEncoder using the CSVEncoder.async(_:) method.

    See more

    Declaration

    Swift

    public final class CSVAsyncEncoder
  • Decodes CSV document data to Swift types.

    This example shows how a simple Person type will be decoded from a CSV document. Personconforms toCodable, so it is compatible with both theCSVEndocderandCSVDecoder`.

    struct Person: Codable {
       let firstName: String,
       let lastName: String,
       let age: Int
    }
    
    let csv = """
    "firstName","lastName","age"
    "Grace","Hopper","113"
    "Linus","Torvold","50"
    """
    let data = Data(csv.utf8)
    
    let people = try CSVDecoder.sync.decode(Person.self, from: data)
    print(people.map { $0.firstName }) // Prints: `["Grace","Linus"]`
    
    See more

    Declaration

    Swift

    public final class CSVDecoder
  • A decoder for decoding a single CSV document all at once.

    You can get an instance of CSVSyncDecoder from the CSVDecoder.sync property.

    See more

    Declaration

    Swift

    public final class CSVSyncDecoder
  • A decoder for decoding sections of a CSV document at different times.

    You can get an instance of CSVAsyncDecoder from the CSVDecoder.async(for:length_:) method.

    See more

    Declaration

    Swift

    public final class CSVAsyncDecoder
  • A synchronous wrapper for the Parser type for parsing whole CSV documents at once.

    See more

    Declaration

    Swift

    public final class SyncParser