Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 903
Yonatan Bensimon Avatar asked Jan 07 '20 22:01

Yonatan Bensimon


1 Answers

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.

like image 52
Alexander Avatar answered Oct 29 '22 13:10

Alexander