How to create an alphabetical section index for a List in SwiftUI?

2.4k Views Asked by At

I would like to know how I can filter my list and create an alphabetical section index to the side of a List in SwiftUI, as is possible with the sectionIndexTitlesForTableView UITableViewDataSource delegate method in UIKit.

Here is an example of what I would like to do

How can I do this?

Here is the list I have so far: List built so far

1

There are 1 best solutions below

0
On

If you're looking for a similar delegate method in SwiftUI you won't find one. Not yet at least.

I would suggest building a separate VStack of the section indexes (array you built already as you normally would for the delegate). Then just wrap your section indexes and your List in a ZStack.