To create a list of strings in SwiftUI, you can use the List
view and provide it with an array of strings. Here's an example:
main.swift200 chars10 lines
In this example, we have an array of fruits which we will use to create the list. We pass the array to the List
view, provide it with a unique identifier using id: \.self
, and then specify what we want to display for each item in the list using a closure with a Text
view.
The result will be a list with each fruit in its own row, like this:
gistlibby LogSnag