Post

Replies

Boosts

Views

Activity

Reply to Filter array by String
Yes, groupArray is a dictionary. The complete code is: struct ResultView: View {   @State var websites : [Website]   @Binding var text : String   @State var groupedArray : [String: [Website]] = [:]   var body: some View {               List{               ForEach(groupedArray.keys.sorted().filter{         text.isEmpty || $0.contains(text)       }, id: \.self){key in         Section(header: Text(key)) {           ForEach(groupedArray[key]!, id: \.self){website in             NavigationLink(               destination: WebView(website: website, url: URL(string: website.url)),               label: {                 Text(website.name)                 Spacer()                 if website.image != ""{                   RemoteImage(url: website.image).frame(width: 25, height: 25, alignment: .center)                                     }else{                   Loader()                 }               })           }         }       }     }.frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height, alignment: .center)        .navigationBarTitle("Results")           .colorScheme(.light)     .onAppear {                                       groupedArray = Dictionary(         grouping: websites,         by: {$0.name.first?.uppercased() ?? ""}       ).mapValues{$0.sorted()}                             }   }         } struct Loader : UIViewRepresentable{   func makeUIView(context: UIViewRepresentableContext<Loader>) -> UIActivityIndicatorView {     let indicator = UIActivityIndicatorView(style: .large)     indicator.startAnimating()     return indicator   }       func updateUIView(_ uiView: UIActivityIndicatorView, context: UIViewRepresentableContext<Loader>) {         } } I have this method from a tutorial, but there wasn't the filter method so I wrote it behind the keys in the ForEach. I don't know if thats right. The content is from a database but the array looks like this: @State var websites = [Website] = [Website(url: "https://www.apple.com/", name: "Apple", image: "Apple.png" , calls: 0), Website(url: "https://www.amazon.com/", name: "Amazon", image: "Amazon.png" , calls: 0)] Is that all you need to know?
Dec ’20
Reply to ImagePicker in SwiftUI
Hi, I did what you said me and when I want to add the "inputImage" to the "listItems" Array, I get the error: Cannot convert value of type 'Image?' to expected argument type 'String'. Do I have to change the "image" in the struct "Item" to Data?: struct Item : Identifiable, Codable{   var id = UUID()   var name : String   var birthday : String   var image : String     }
Dec ’20
Reply to Create a swift file with swift
I started developing a game with Firebase and Firebase database. If the app should start if such a Swift file does not already exist, a user will be created. Then a Swift file is created by notifying the randomly generated email address. If the app is then restarted, the code should recognise that the file exists and log in with the email address noted there. Then the variables can be read out of the database.
Jul ’20