CSVParser

public class CSVParser

Undocumented

  • Creates a new CSV parser

    Declaration

    Swift

    public init(inputStream: InputStream, delimiter: UInt8 = 0x2C, hasHeader: Bool = false, header: [String]? = nil)

    Parameters

    inputStream

    The input stream for CSVParser to use to read data from

    delimiter

    Delimiter to be used to signify a new column

    hasHeader

    Indicates whether the CSV contains a header

    header

    Manually set a header (if set, hasHeader will be disregarded)

  • Returns the next item parsed as Array of Strings (if not further rows avaliable, returns nil)

    Declaration

    Swift

    public func next() -> [String]?
  • Returns the next item parsed as given Decodable (if not further rows avaliable, returns nil)

    Precondition

    header is set, or hasHeader is true, and CSV contains a header

    Declaration

    Swift

    public func next<T>(as: T.Type) throws -> T? where T : Decodable

    Parameters

    as

    Type that should be used for decoding

  • Returns the next item as a dictionary (if not further rows avaliable, returns nil)

    Precondition

    header is set, or hasHeader is true, and CSV contains a header

    Declaration

    Swift

    public func nextAsDict() throws -> [String : String]?
  • Loads all rows from CSV as String Array

    Declaration

    Swift

    public func loadAll(rowCount: Int? = nil) -> [[String]]?

    Parameters

    rowCount

    Optional, amount of expected rows

    Return Value

    Array of String Arrays, with each top-level Array Entry representing one row, and each element of given Entry representing one column

  • Loads all rows from CSV as Dictionary ([String: String])

    Precondition

    header is set, or hasHeader is true, and CSV contains a header

    Declaration

    Swift

    public func loadAllAsDict(rowCount: Int? = nil) throws -> [[String : String]]?

    Parameters

    rowCount

    Optional, amount of expected rows

    Return Value

    Array of Dictionaries, with each Dictionary representing one row

  • Loads all rows from CSV and parses them as given Decodable

    Precondition

    header is set, or hasHeader is true, and CSV contains a header

    Declaration

    Swift

    public func loadAll<T>(as: T.Type, rowCount: Int? = nil) throws -> [T]? where T : Decodable

    Parameters

    as

    Type that should be used for decoding

    rowCount

    Optional, amount of expected rows

Init from URL

Init with Data

Init with String