SwiftUI_visionOS_Note

How to use List()

Jan 4, 2024
  • VStack with a list
  • List makes modifying and editing super easy.
 

1. Create a list with list of text

  • Simply use List() and Text() to create a base code
 

2. Use array and ForEach()

  • First, we create array of string named fruits including list of fruits.
  • Import fruits into ForEach.
    • Declare the id with \.self
      • fruit in will write each array of string value
  • .capitalized after the text will make it capitaliezd
 
 

3. Add a Section of the list

  • Section() will create header: and content:
    • We write a header text on the header
      • header: {Text("Fruits)}
    • and we add a content in the curly brackets
 
 

4. Delete an Item (Swipe)

  • add .onDelete(perform: delete) after Section{content}

  • onDelete will perform delete from function we created.
 

  • Now we can swipe to delete
 

5. Delete an Item (Edit)

  • By adding EditButton() on the toolbar will perform the edit
  • by clicking edit, delete button will show on the list

#toolbar

 

6. Move an Item (Edit)

  • Add .onMove after Section{}
 
  • Extract the function to make it simpler
 
  • Rewrite .onMove
 
 

7. Add an Item .append()

  • Add .topBarTrailing as a new toolbar button
  • Add a button with .append string value.
    • Pressing a button will add “peach” in the fruits array
 
  • Extract button function
 
  • Extract the button as a separate View
 
  • We can simplify the toolBarItem
 
 

8. Add a list style

  • We can change the style of list by adding .listStyle()
    • Most of styles aren’t supported in VisionOS

Apple developer (List of Style)

 
 

9. List Style

 
 
 
  • Creating a list with an array of text, adding sections, deleting items, moving items, and adding new items.
  • Changing the list style
  • Extracting functions and views
 
 

#visionOS #applevisionpro #swiftUI #appdevelopment

 

This video provides the opportunity to experience a spatial video on my Quest 2. The immersion was remarkable, similar to viewing a 3D movie up close with 3D glasses. However, I noticed that the performance fell short when it came to distant fixtures, scenes, or panoramic views. #VR #SpatialVideo #Quest2

\\

This video provides the opportunity to experience spatial video on my Quest 2. The immersion was remarkable, similar to viewing a 3D movie up close with 3D glasses. However, the performance was lacking when it came to distant fixtures, scenes, or panoramic views.

You might also like

BlogPro logo
Made with BlogPro