diff --git a/Sources/CSwiftV.swift b/Sources/CSwiftV.swift index 50f8326..70f9283 100644 --- a/Sources/CSwiftV.swift +++ b/Sources/CSwiftV.swift @@ -38,8 +38,8 @@ public class CSwiftV { /// - Parameter headers: The array of headers from the file. If not included, it will be populated with the ones from the first line public init(with string: String, separator: String = ",", headers: [String]? = nil) { - var parsedLines = CSwiftV.records(from: string.replacingOccurrences(of: "\r\n", with: "\n")).map { CSwiftV.cells(forRow: $0, separator: separator) } - self.headers = headers ?? parsedLines.removeFirst() + var parsedLines = CSwiftV.records(from: string.replacingOccurrences(of: "\r\n", with: "\n")).map({ CSwiftV.cells(forRow: $0, separator: separator) }) + self.headers = parsedLines.count == 0 ? [] : (headers ?? parsedLines.removeFirst()) rows = parsedLines columnCount = self.headers.count @@ -105,3 +105,4 @@ public class CSwiftV { } } +