GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

Day 77 Milestone: Projects 13-15

Forums > 100 Days of SwiftUI

@Moghi  

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 Notes).

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.

2      

Hacking with Swift is sponsored by Essential Developer.

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until February 9th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.