I have an app that has to show several images (in a LazyVGrid), and I want to check if a specific word is present in a specific field of a JSON file that the app loads at start. It is possible?
Waiting for help, thank you!
Here's the code for the View:
import SwiftUI
import URLImage
struct GalleryView: View {
let columns = [
GridItem(.flexible()),
GridItem(.flexible()),
]
@ObservedObject var dm: DownloadManager
var body: some View {
ScrollView {
LazyVGrid(columns: columns) {
ForEach(dm.JSON) { busso in
NavigationLink(
destination: ImageView(busso: busso)) {
VStack(alignment: .center) {
URLImage(URL(string: busso.fotoUrl) ?? furl)
.resizable()
.aspectRatio(contentMode: .fit)
Text(busso.titolo)
.font(.headline)
}
}
}
}
}
.padding(.top, 8.0)
.navigationBarTitle("Galleria", displayMode: .inline)
}
}
struct GalleryView_Previews: PreviewProvider {
static var previews: some View {
GalleryView(dm: DownloadManager())
}
}
Here's the code of the JSON file (I want the app to check for the word "image" in the "extra1" field, if possible)
[
{
"id": "3",
"titolo": "Panorama",
"autore": "Descrizione",
"testo": "",
"data": "",
"extra1": "image",
"extra2": "",
"creazione": "2021-01-07 11:21:53",
"foto": "foto/WP_20161110_001.jpg",
"fotoUrl": "http://geniuspointfrezza.altervista.org/foto/WP_20161110_001.jpg"
},
{
"id": "2",
"titolo": "Comune di Busso",
"autore": "Contatti",
"testo": "Indirizzo, telefono, mail, altri dati da inserire",
"data": "",
"extra1": "",
"extra2": "",
"creazione": "2021-01-01 19:33:56",
"foto": "foto/DSCN0914.JPG",
"fotoUrl": "http://geniuspointfrezza.altervista.org/foto/DSCN0914.JPG"
},
{
"id": "1",
"titolo": "Chiesa",
"autore": "Luoghi da visitare",
"testo": "Testo di prova, abbastanza lungo per verificare l'impaginazione e correggere eventuali errori.",
"data": "",
"extra1": "",
"extra2": "",
"creazione": "2021-01-01 19:32:02",
"foto": "foto/CAM_0044.JPG",
"fotoUrl": "http://geniuspointfrezza.altervista.org/foto/CAM_0044.JPG"
}
]