I am coding the assignment where we create notes with images. Loading an image and naming it immediatly.
I created a new struct Note
to store a swiftUI image and a string:
struct Note: Identifiable {
var id: UUID
var image: Image
var text: String
static var previewData: Note {
return Note(id: UUID(), image: Image(systemName: "photo"), text: "Some note you wrote.")
}
}
After an image is picked with ImagePicker
the function loadImage()
is called to create a swiftUI image view:
func loadImage() {
guard let inputImage = inputImage else { return }
let image = Image(uiImage: inputImage)
newNote = Note(id: UUID(), image: image, text: "")
showingAddNote = true
// notes.append(newNote)
}
That's where I thought I could create a new note, ask for text-input from the user, wait for the input and use the
dismiss-action of the edit-view to store my new note by appending it to a state variable notes
(an array of Note
s).
But since the function can only indirectly "show" a view by setting a boolean, how would I give the view access to the
freshly created note? The idea is that the view adds whatever the user inputs as text.