Member-only story
ListFormatter: The Missing Documentation
It’s a little bit great
Difficulty: Beginner | Easy | Normal | Challenging
From iOS 13 Apple made a ListFormatter available — but skimped rather on the documentation. Hopefully this rather short article can help you out!
This article has been developed using Xcode 12.0, and Swift 5.3
Prerequisites:
You will be expected to be aware how to make a Single View Application in Swift, or use Playgrounds to do the same
The problem to be solved
We have three names, and we wish to write these as a list separated with commas.
In Swift we have the
let names = [“Livesh”, “Romesh”, “Chau”, “Bella”]
and I would like a **sample output** of
Livesh, Romesh, Chau, and Bella
So how can I achieve this?
There are two ways, I’ll call one the old way, and one the ListFormatter way.
The Old Way
I’ll need to know how many elements there are in an Array, and process a new String.