[ad_1]
I’ve an array that comprises the info that’s displayed on an inventory. When the consumer hits “new”, a sheet pops as much as enable the consumer to enter a brand new merchandise to the listing.
I simply added a swipe choice to edit this merchandise and I needed to reuse the identical sheet to edit the merchandise’s textual content. However I am having issues understanding find out how to examine whether or not a particular merchandise was chosen (by UUID?) to move to the sheet, or it is a new merchandise.
Code:
let dateFormatter = DateFormatter()
struct NoteItem: Codable, Hashable, Identifiable {
let id: UUID
var textual content: String
var date = Date()
var dateText: String {
dateFormatter.dateFormat = "EEEE, MMM d yyyy, h:mm a"
return dateFormatter.string(from: date)
}
var tags: [String] = []
}
struct ContentView: View {
@EnvironmentObject non-public var information: DataModel
@State non-public var selectedItemId: UUID?
@State var searchText: String = ""
@State non-public var sheetIsShowing = false
NavigationView {
Checklist(filteredNotes) { word in
VStack(alignment: .main) {
//....
// not related code
}
.swipeActions(allowsFullSwipe: false) {
Button(motion: {
selectedItemId = word.id
self.sheetIsShowing = true
} ) {
Label("Edit", systemImage: "pencil")
}
}
}
.toolbar {
// new merchandise
Button(motion: {
self.sheetIsShowing = true
}) {
Picture(systemName: "sq..and.pencil")
}
}
.sheet(isPresented: $sheetIsShowing) {
if self.selectedItemId == NULL { // <-- that is giving me an error
let Observe = NoteItem(id: UUID(), textual content: "New Observe", date: Date(), tags: [])
SheetView(isVisible: self.$sheetIsShowing, word: Observe)
} else {
let index = information.notes.firstIndex(of: selectedItemId)
SheetView(isVisible: self.$sheetIsShowing, word: information.notes[index])
}
}
}
}
My rationale was to examine whether or not self.selectedItemId == NULL was null or not, if not then move that ingredient to the sheet to be edited, if sure, the because it as a brand new ingredient.
What am I doing unsuitable? And if there’s a normal option to move data to the sheet primarily based on whether or not there may be an merchandise choose or not, may you present me?
Thanks!
[ad_2]
