Creating a CSV Export library for Swift (Part 1)

Scott Matthewman
6 min readJan 3, 2024
Data analysis is the goal — CSV is often the interchange format of choice. Photo by Lukas Blazek on Unsplash

m currently building a large and rather complicated app in SwiftUI that involves quite a lot of data. While the app handles most tasks internally, there are some features of spreadsheets like Excel or Numbers that could do a better job of analysing the data, and there are some tabular views that I’d want to share with people who don’t have a copy of the app.

One of the best supported file formats for sharing tabular data is CSV (comma separated value). This represents
tabular data as one line of text per row, with each item separated by commas. For example, the table:

would be expressed as

ID,Full Name,Description,First appearance
1,William Hartnell,Later played by Richard Hurndall and David Bradley,1963–11–23
2,Patrick Troughton,,1966–11–05
3,Jon Pertwee,,1970–01–03
4,Tom Baker,"No relation to the Sixth Doctor, Colin Baker",1974–12–28

The Swift Package Index has a fair few CSV parsers available, and there
are several that would do the job. But none of them quite works in the way I want, or has the exact feature set that I require.

--

--

Scott Matthewman

Scott is a software developer during the day and a theatre critic & director of an evening. Which is the worst superhero identity ever.