how do i integrate functions in swiftui in order to create reusable code with input dictionaries?

Separate mentioned VStack into dedicated view and use it with input data, like below (tested with Xcode 12 / iOS 14)

struct ReuseContentView: View {
    var body: some View {
        VStack {
            DictionaryView(data: primary)
            DictionaryView(data: secondary)
        }
    }
}

struct DictionaryView: View {
    let data: [String: String]
    var body: some View {
        VStack {
            List{
                ForEach(Array(primary), id: \.key) { key, value in
                    HStack {
                        Text(key)
                            .fontWeight(.light)
                            .padding()
                        Spacer()
                        Text(value)
                            .fontWeight(.light)
                            .padding()
                    }
                    
                }
            }
        }
    }
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top