What is CSVImporter and why is it needed?
CSVImporter is a lightweight library for Swift (iOS/macOS) that simplifies importing, parsing, and exporting CSV files. Unlike standard Foundation, CSVImporter provides ready-made tools for processing large tabular data, automatic delimiter detection, and working with encodings. The library is ideal for applications that require loading data from external sources: accounting reports, contact lists, datasets for machine learning, or configuration files.
Installation
CSVImporter is installed via Swift Package Manager. Add the dependency in Package.swift:
.package(url: "https://github.com/Flinesoft/CSVImporter.git", from: "1.9.0")Or via Xcode: File → Add Packages → paste the repository URL.
Main Features
- Automatic delimiter detection — supports commas, semicolons, tabs.
- Streaming parsing — processes files of any size without loading them entirely into memory.
- Encoding support — UTF-8, Windows-1251, ISO Latin-1.
- Flexible typing — conversion of strings to Int, Double, Date, and custom structures.
- Export — creating CSV from arrays of dictionaries.
Swift Code Example
import CSVImporter
// Import from filelet path = Bundle.main.path(forResource: "data", ofType: "csv")!let importer = CSVImporter<[String]>(path: path)let records = importer.importRecords { $0 } // [["Name", "Age"], ["Alice", "30"], ...]
// Parsing with headerslet structured = importer.importRecords { record in return Person(name: record[0], age: Int(record[1]) ?? 0)}
// Exportlet data = [["Name", "Age"], ["Bob", "25"]]let csvString = data.csvString() // "Name,AgeBob,25"try? csvString.write(to: URL(fileURLWithPath: "/tmp/output.csv"), atomically: true, encoding: .utf8)When to use CSVImporter?
- When working with tabular data from Excel/Google Sheets.
- In applications for financial analysis, inventory management, or statistics tracking.
- When migrating data between services (e.g., importing contacts from CSV).
- In macOS utilities for processing logs or configurations.
The library is stable, has 100% test coverage, and has been supported by the community since 2016. Suitable for iOS 13+, macOS 10.15+.