{"id":15717783,"url":"https://github.com/swiftcsv/swiftcsv","last_synced_at":"2025-12-18T16:07:27.026Z","repository":{"id":717509,"uuid":"20652131","full_name":"swiftcsv/SwiftCSV","owner":"swiftcsv","description":"CSV parser for Swift","archived":false,"fork":false,"pushed_at":"2024-07-17T03:41:15.000Z","size":333,"stargazers_count":1034,"open_issues_count":13,"forks_count":194,"subscribers_count":31,"default_branch":"master","last_synced_at":"2025-05-15T12:04:19.986Z","etag":null,"topics":["csv","ios","mac","macos","parser","swift","tsv"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":"Deprecated","scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/swiftcsv.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-06-09T15:46:27.000Z","updated_at":"2025-05-14T10:16:28.000Z","dependencies_parsed_at":"2023-07-06T10:46:03.502Z","dependency_job_id":"1a261cd6-146f-4e17-9374-4c5a52b7970a","html_url":"https://github.com/swiftcsv/SwiftCSV","commit_stats":{"total_commits":161,"total_committers":31,"mean_commits":5.193548387096774,"dds":0.7329192546583851,"last_synced_commit":"6ab5d0fe9b6ef3c79d717eefa70862df389e74d9"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftcsv%2FSwiftCSV","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftcsv%2FSwiftCSV/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftcsv%2FSwiftCSV/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftcsv%2FSwiftCSV/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swiftcsv","download_url":"https://codeload.github.com/swiftcsv/SwiftCSV/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254337612,"owners_count":22054253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csv","ios","mac","macos","parser","swift","tsv"],"created_at":"2024-10-03T21:51:20.005Z","updated_at":"2025-12-18T16:07:26.943Z","avatar_url":"https://github.com/swiftcsv.png","language":"Swift","readme":"# SwiftCSV\n\n[![Platform support](https://img.shields.io/badge/platform-ios%20%7C%20osx%20%7C%20tvos%20%7C%20watchos-lightgrey.svg?style=flat-square)](https://github.com/swiftcsv/SwiftCSV/blob/master/LICENSE.md)\n[![Build Status](https://img.shields.io/travis/swiftcsv/SwiftCSV/master.svg?style=flat-square)](https://travis-ci.org/swiftcsv/SwiftCSV)\n[![Code coverage status](https://codecov.io/gh/swiftcsv/SwiftCSV/branch/master/graph/badge.svg)](https://codecov.io/gh/swiftcsv/SwiftCSV)\n[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/SwiftCSV.svg?style=flat-square)](https://cocoapods.org/pods/SwiftCSV)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![License MIT](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/swiftcsv/SwiftCSV/blob/master/LICENSE.md)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fswiftcsv%2FSwiftCSV%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/swiftcsv/SwiftCSV)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fswiftcsv%2FSwiftCSV%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/swiftcsv/SwiftCSV)\n\nSimple CSV parsing for macOS, iOS, tvOS, and watchOS.\n\n## Usage\n\nCSV content can be loaded using the `CSV` class:\n\n```swift\nimport SwiftCSV\n\ndo {\n    // As a string, guessing the delimiter\n    let csv: CSV = try CSV\u003cNamed\u003e(string: \"id,name,age\\n1,Alice,18\")\n\n    // Specifying a custom delimiter\n    let tsv: CSV = try CSV\u003cEnumerated\u003e(string: \"id\\tname\\tage\\n1\\tAlice\\t18\", delimiter: .tab)\n\n    // From a file (propagating error during file loading)\n    let csvFile: CSV = try CSV\u003cNamed\u003e(url: URL(fileURLWithPath: \"path/to/users.csv\"))\n\n    // From a file inside the app bundle, with a custom delimiter, errors, and custom encoding.\n    // Note the result is an optional.\n    let resource: CSV? = try CSV\u003cNamed\u003e(\n        name: \"users\",\n        extension: \"tsv\",\n        bundle: .main,\n        delimiter: .character(\"🐠\"),  // Any character works!\n        encoding: .utf8)\n} catch parseError as CSVParseError {\n    // Catch errors from parsing invalid CSV\n} catch {\n    // Catch errors from trying to load files\n}\n```\n\n### File Loading\n\nThe `CSV` class comes with initializers that are suited for loading files from URLs.\n\n```swift\nextension CSV {\n    /// Load a CSV file from `url`.\n    ///\n    /// - Parameters:\n    ///   - url: URL of the file (will be passed to `String(contentsOfURL:encoding:)` to load)\n    ///   - delimiter: Character used to separate separate cells from one another in rows.\n    ///   - encoding: Character encoding to read file (default is `.utf8`)\n    ///   - loadColumns: Whether to populate the columns dictionary (default is `true`)\n    /// - Throws: `CSVParseError` when parsing the contents of `url` fails, or file loading errors.\n    public convenience init(url: URL,\n                            delimiter: CSVDelimiter,\n                            encoding: String.Encoding = .utf8,\n                            loadColumns: Bool = true) throws\n\n    /// Load a CSV file from `url` and guess its delimiter from `CSV.recognizedDelimiters`, falling back to `.comma`.\n    ///\n    /// - Parameters:\n    ///   - url: URL of the file (will be passed to `String(contentsOfURL:encoding:)` to load)\n    ///   - encoding: Character encoding to read file (default is `.utf8`)\n    ///   - loadColumns: Whether to populate the columns dictionary (default is `true`)\n    /// - Throws: `CSVParseError` when parsing the contents of `url` fails, or file loading errors.\n    public convenience init(url: URL,\n                            encoding: String.Encoding = .utf8,\n                            loadColumns: Bool = true)\n}\n```\n\n### Delimiters\n\nDelimiters are strongly typed. The recognized `CSVDelimiter` cases are: `.comma`, `.semicolon`, and `.tab`.\n\nYou can use convenience initializers that guess the delimiter from the recognized list for you. These initializers are available for loading CSV from URLs and strings.\n\nYou can also use any other single-character delimiter when loading CSV data. A character literal like `\"x\"` will produce `CSV.Delimiter.character(\"x\")`, so you don't have to type the whole `.character(_)` case name. There are initializers for each variant that accept explicit delimiter settings.\n\n### Reading Data\n\n```swift\n// Recognized the comma delimiter automatically:\nlet csv = CSV\u003cNamed\u003e(string: \"id,name,age\\n1,Alice,18\\n2,Bob,19\")\ncsv.header         //=\u003e [\"id\", \"name\", \"age\"]\ncsv.rows           //=\u003e [[\"id\": \"1\", \"name\": \"Alice\", \"age\": \"18\"], [\"id\": \"2\", \"name\": \"Bob\", \"age\": \"19\"]]\ncsv.columns        //=\u003e [\"id\": [\"1\", \"2\"], \"name\": [\"Alice\", \"Bob\"], \"age\": [\"18\", \"19\"]]\n```\n\nThe rows can also parsed and passed to a block on the fly, reducing the memory needed to store the whole lot in an array:\n\n```swift\n// Access each row as an array (inner array not guaranteed to always be equal length to the header)\ncsv.enumerateAsArray { array in\n    print(array.first)\n}\n// Access them as a dictionary\ncsv.enumerateAsDict { dict in\n    print(dict[\"name\"])\n}\n```\n\n### Skip Named Column Access for Large Data Sets\n\nUse `CSV\u003cNamed\u003e` aka `NamedCSV` to access the CSV data on a column-by-column basis with named columns. Think of this like a cross section:\n\n```swift\nlet csv = NamedCSV(string: \"id,name,age\\n1,Alice,18\\n2,Bob,19\")\ncsv.rows[0][\"name\"]  //=\u003e \"Alice\"\ncsv.columns[\"name\"]  //=\u003e [\"Alice\", \"Bob\"]\n```\n\nIf you only want to access your data row-by-row, and not by-column, then you can use `CSV\u003cEnumerated\u003e` or `EnumeratedCSV`:\n\n```swift\nlet csv = EnumeratedCSV(string: \"id,name,age\\n1,Alice,18\\n2,Bob,19\")\ncsv.rows[0][1]          //=\u003e \"Alice\"\ncsv.columns?[0].header  //=\u003e \"name\"\ncsv.columns?[0].rows    //=\u003e [\"Alice\", \"Bob\"]\n```\n\nTo speed things up, skip populating by-column access completely by passing `loadColumns: false`. This will prevent the columnar data from being populated. For large data sets, this saves a lot of iterations (at quadratic runtime).\n\n```swift\nlet csv = EnumeratedCSV(string: \"id,name,age\\n1,Alice,18\\n2,Bob,19\", loadColumns: false)\ncsv.rows[0][1]  //=\u003e \"Alice\"\ncsv.columns     //=\u003e nil\n```\n\n\n## Installation\n\n### CocoaPods\n\n```ruby\npod \"SwiftCSV\"\n```\n\n### Carthage\n\n```\ngithub \"swiftcsv/SwiftCSV\"\n```\n\n### SwiftPM\n\n```\n.package(url: \"https://github.com/swiftcsv/SwiftCSV.git\", from: \"0.8.0\")\n```\n\n## Privacy Manifest\n\nThe package ships with an empty Privacy Manifest because it doesn't access or track any sensitive data.   \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswiftcsv%2Fswiftcsv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswiftcsv%2Fswiftcsv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswiftcsv%2Fswiftcsv/lists"}