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
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
121
109
122
```swift
110
123
let reader =tryCSVReader(input: string) { $0.headerStrategy= .firstLine }
111
-
112
124
let headers = reader.headers// ["numA", "numB", "numC"]
113
125
114
126
let recordA =try reader.readRecord()
115
-
let rowA = recordA.row// ["1", "2", "3"]
116
-
letfirstField= recordA[0] // "1"
117
-
letsecondField= recordA["numB"] // "2"
127
+
let rowA = recordA.row// ["1", "2", "3"]
128
+
letfieldA= recordA[0]// "1"
129
+
letfieldB= recordA["numB"]// "2"
118
130
119
131
let recordB =try reader.readRecord()
120
132
```
@@ -130,7 +142,7 @@ A `CSVReadder` parses CSV data from a given input (`String`, or `Data`, or file)
130
142
131
143
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
144
133
-
### Reader configuration
145
+
### Reader Configuration
134
146
135
147
`CSVReader` accepts the following configuration properties:
136
148
@@ -232,7 +244,7 @@ A `CSVWriter` encodes CSV information into a specified target (i.e. a `String`,
232
244
233
245
`CSVWriter` enforces this by throwing an error when you try to write more the expected amount of fields, or filling a row with empty fields when you call `endRow()` but not all fields has been written.
234
246
235
-
### Writer configuration
247
+
### Writer Configuration
236
248
237
249
`CSVWriter` accepts the following configuration properties:
238
250
@@ -298,7 +310,7 @@ You can get all the information by simply printing the error or calling the `loc
298
310
</p></details>
299
311
</ul>
300
312
301
-
## `Codable`'s decoder/encoder
313
+
## Declarative Decoder/Encoder
302
314
303
315
The encoders/decoders provided by this library let you use Swift's `Codable` declarative approach to encode/decode CSV data.
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.
323
335
324
-
### Decoder configuration
336
+
### Decoder Configuration
325
337
326
-
The decoding process can be tweaked by specifying configuration values at initialization time. `CSVDecoder` accepts the [same configuration values as `CSVReader`](#Reader-configuration) plus the following ones:
338
+
The decoding process can be tweaked by specifying configuration values at initialization time. `CSVDecoder` accepts the [same configuration values as `CSVReader`](#Reader-Configuration) plus the following ones:
327
339
328
340
- `nilStrategy` (default: `.empty`) indicates how the `nil` *concept* (absence of value) is represented on the CSV.
If you are dealing with a big CSV content, it is preferred to use direct file encoding and a `.sequential` or `.assembled` buffering strategy, since then memory usage is drastically reduced.
379
391
380
-
### Encoder configuration
392
+
### Encoder Configuration
381
393
382
-
The encoding process can be tweaked by specifying configuration values. `CSVEncoder` accepts the [same configuration values as `CSVWriter`](#Writer-configuration) plus the following ones:
394
+
The encoding process can be tweaked by specifying configuration values. `CSVEncoder` accepts the [same configuration values as `CSVWriter`](#Writer-Configuration) plus the following ones:
383
395
384
396
- `nilStrategy` (default: `.empty`) indicates how the `nil` *concept* (absence of value) is represented on the CSV.
Copy file name to clipboardExpand all lines: sources/Active/Reader/Reader.swift
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -65,7 +65,7 @@ public final class CSVReader: IteratorProtocol, Sequence {
65
65
66
66
extensionCSVReader{
67
67
/// Advances to the next row and returns it, or `nil` if no next row exists.
68
-
/// - warning: If the CSV file being parsed contains invalid characters, this function will crash. For safer parsing use `readRow()`.
68
+
/// - warning: If the CSV file being parsed contains invalid characters, this function will crash. For safer parsing use `readRow()` or `readRecord()`.
0 commit comments