You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9-9Lines changed: 9 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -80,7 +80,7 @@ A `CSVReadder` parses CSV data from a given input (`String`, or `Data`, or file)
80
80
81
81
```swift
82
82
let data: Data =...
83
-
let result =try CSVReader.parse(input: data)
83
+
let result =try CSVReader.decode(input: data)
84
84
85
85
// `result` lets you access the CSV headers, all CSV rows, or access a specific row/record. For example:
86
86
let headers = result.headers// [String]
@@ -100,23 +100,23 @@ A `CSVReadder` parses CSV data from a given input (`String`, or `Data`, or file)
100
100
let reader =tryCSVReader(input: string) { $0.headerStrategy= .firstLine }
101
101
102
102
let headers = reader.headers// ["numA", "numB", "numC"]
103
-
let rowA =try reader.parseRow() // ["1", "2", "3"]
104
-
let rowB =try reader.parseRow() // ["4", "5", "6"]
103
+
let rowA =try reader.readRow() // ["1", "2", "3"]
104
+
let rowB =try reader.readRow() // ["4", "5", "6"]
105
105
```
106
106
107
-
Alternatively you can use the `parseRecord()` function which also returns the next CSV row, but it wraps the result in a convenience structure. This structure lets you access each field with the header name (as long as the `headerStrategy` is marked with `.firstLine`).
107
+
Alternatively you can use the `readRecord()` function which also returns the next CSV row, but it wraps the result in a convenience structure. This structure lets you access each field with the header name (as long as the `headerStrategy` is marked with `.firstLine`).
108
108
109
109
```swift
110
110
let reader =tryCSVReader(input: string) { $0.headerStrategy= .firstLine }
111
111
112
112
let headers = reader.headers// ["numA", "numB", "numC"]
113
113
114
-
let recordA =try reader.parseRecord()
114
+
let recordA =try reader.readRecord()
115
115
let rowA = recordA.row// ["1", "2", "3"]
116
116
let firstField = recordA[0] // "1"
117
117
let secondField = recordA["numB"] // "2"
118
118
119
-
let recordB =try reader.parseRecord()
119
+
let recordB =try reader.readRecord()
120
120
```
121
121
122
122
- `Sequence` syntax parsing.
@@ -128,7 +128,7 @@ A `CSVReadder` parses CSV data from a given input (`String`, or `Data`, or file)
128
128
}
129
129
```
130
130
131
-
Please note the `Sequence` syntax (i.e. `IteratorProtocol`) doesn't throw errors; therefore if the CSV data is invalid, the previous code will crash. If you don't control the CSV data origin, use `parseRow()` instead.
131
+
Please note the `Sequence` syntax (i.e. `IteratorProtocol`) doesn't throw errors; therefore if the CSV data is invalid, the previous code will crash. If you don't control the CSV data origin, use `readRow()` instead.
132
132
133
133
### Reader configuration
134
134
@@ -315,11 +315,11 @@ let result = try decoder.decode(CustomType.self, from: data)
315
315
`CSVDecoder` can decode CSVs represented as a `Data` blob, a `String`, or an actual file in the file system.
316
316
317
317
```swift
318
-
let decoder = CSVDecoder { $0.bufferingStrategy = .assembled }
318
+
let decoder = CSVDecoder { $0.bufferingStrategy = .sequential }
319
319
let content: [Student] = try decoder([Student].self, from: URL("~/Desktop/Student.csv"))
320
320
```
321
321
322
-
If you are dealing with a big CSV file, it is preferred to used direct file decoding, a `.sequential` or `.assembled` buffering strategy, and set *presampling* to false; since then memory usage is drastically reduced.
322
+
If you are dealing with a big CSV file, it is preferred to used direct file decoding, a `.sequential` or `.unrequested` buffering strategy, and set *presampling* to false; since then memory usage is drastically reduced.
0 commit comments