The new CaseIterable protocol gives your Enum new ability to generate an array of all cases in an enum.

Pasta example from https://www.hackingwithswift.com/articles/77/whats-new-in-swift-4-2

1
2
3
4
5
6
7
enum Pasta: CaseIterable {
case cannelloni, fusilli, linguine, tagliatelle
}

for pasta in Pasta.allCases {
print(pasta)
}

Print out:

1
2
3
4
cannelloni
fusilli
linguine
tagliatelle

Then you can easily generate data for table view.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
enum Pasta: CaseIterable {
case conchiglie, fusilli, linguine, tagliatelle

var name: String {
switch self {
case .conchiglie: return "Conchiglie"
case .fusilli: return "Fusilli"
case .linguine: return "Linguine"
case .tagliatelle: return "Tagliatelle"
}
}

var shape: String {
switch self {
case .conchiglie: return "Shells"
case .fusilli: return "Twists"
case .linguine: return "Long and skinny"
case .tagliatelle: return "Long ribbons"
}
}

var image: UIImage {
switch self {
case .conchiglie: return UIImage(named: "conchiglie")!
case .fusilli: return UIImage(named: "fusilli")!
case .linguine: return UIImage(named: "linguine")!
case .tagliatelle: return UIImage(named: "tagliatelle")!
}
}
}

// Generate data for the table view
var objectsForTableView: [Pasta] = Pasta.allcases
...

Here is the pasta table: