IOS + Swift Swift 5
Swift – create expanding lists
May 9, 2021
0
,

//

//  MainView.swift

//  MySwiftLearning1

//

//  Created by Arifur Rahman Jerin on 4/30/21.

//

import SwiftUI

struct Bookmark: Identifiable {

    let id = UUID()

    let name: String

    let icon: String

    var items: [Bookmark]?

    // some example websites

    static let apple = Bookmark(name: “Apple”, icon: “1.circle”)

    static let bbc = Bookmark(name: “BBC”, icon: “square.and.pencil”)

    static let swift = Bookmark(name: “Swift”, icon: “bolt.fill”)

    static let twitter = Bookmark(name: “Twitter”, icon: “mic”)

    // some example groups

    static let example1 = Bookmark(name: “Favorites”, icon: “star”, items: [Bookmark.apple, Bookmark.bbc, Bookmark.swift, Bookmark.twitter])

    static let example2 = Bookmark(name: “Recent”, icon: “timer”, items: [Bookmark.apple, Bookmark.bbc, Bookmark.swift, Bookmark.twitter])

    static let example3 = Bookmark(name: “Recommended”, icon: “hand.thumbsup”, items: [Bookmark.apple, Bookmark.bbc, Bookmark.swift, Bookmark.twitter])

}

struct MainView: View {

    

    let items: [Bookmark] = [.example1, .example2, .example3]

    

    var body: some View {

        List(items, children: \.items) { row in

                    Image(systemName: row.icon)

                    Text(row.name)

                }

        }

}

Expanding List

About author

ZERIN

CEO & Founder (BdBooking.com - Online Hotel Booking System), CEO & Founder (TaskGum.com - Task Managment Software), CEO & Founder (InnKeyPro.com - Hotel ERP), Software Engineer & Solution Architect

Swift – Add Sections to List

struct Pizzeria: View {     let name: String   ...

Read more

Swift – How to let users delete rows from a list

struct MainView: View {   @State private var user...

Read more

Swift – Carousel Lists on watchOS

List(1..<51) { Text("\($0)") } .listStyle(Carou...

Read more

There are 0 comments

Leave a Reply

Your email address will not be published. Required fields are marked *