Perfect, it works! Thank you for helping
Post
Replies
Boosts
Views
Activity
Hi, Thank you @OOPer. Do you know how to write the little more complex code?
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?
Hi I have the array sorted but I want it like the Contacts app on the iPhone, so that all Strings, whose first letter is "a", are in the Section "A" and so on. Do you understand what I mean?
Hi thank you for your help but the Url i get is "Optional(./ -- file:///)". Do you need some of my code to see what I have to do ?
Hi I converted the image to URL and I get this error when I want to give the URL to AddView, I get the error:
Cannot convert value of type 'Binding<URL>' to expected argument type 'Binding<URL?>'
what can I do there?
I want to store the Image so that I can load the Image later
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
}
I changed it to a String because I want to save the name of the picture in the UserDefaults. Is there a way to do that?
@OOPer In the function loadImage in struct AppView
In the function loadImage in struct AppView
Thank you!
How can I check that?
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.
Otherwise, is it possible to create a text file local on the device and write the data in and then retrieve it in the code?