Your Second iOS and SwiftUI App · Adding to your Model | raywenderlich.com

Yes, me and others. Thank you for asking.

Why did you not use a normal button with the action: {}. You said it would be better with coding it but would it yield the same result if you did the adding of tasks and closing within the action?

I’m sorry, I don’t understand. Can you post the code that you’re imagining for the two alternatives?

Im saying instead of doing:

Button(“Add”) {

self.taskStore.tasks.append(Task(name: self.text))
self.presentationMode.wrappedValue.dismiss()

}

do it like this:

Button(action: {

self.taskStore.tasks.append(Task(name: self.text))
self.presentationMode.wrappedValue.dismiss()

}) {
Text(“Add”
}

the second one would be if u added a button using CMD + Shift + L

The overload I used exists because it’s a common use case: Apple Developer Documentation

Another course that shows what DOESN’T work in SwiftUI right at the beginning of a course for iOS developers. Why don’t you make the course in UIKIT instead where things work fine? It’s another course where the teachers speaks to himself.

Add the below code to the ContentView as well, that seem to fix the bug. It was only in the modelView (NewTaskView).
If you add this line there too, for some reason the add + button works as many times as you want.
What is the reason? Could it be that ContentView does not know the modalView has been closed?

@Environment(.presentationMode) var presentation

I was really scratching my head on the introduction of @Environment() syntax. I think I’ve wrapped my brain around what hoops Swift is jumping through to make this work, but without much confidence.

This line of code looks completely alien as a form of ‘value assignment’ to variable, and the introduction would really benefit from some more explanation of the SwiftUI “magic” that makes this work.

image

1 Like

Thanks for the feedback. Like everything else with an @ in front of it in SwiftUI, Environment is a property wrapper, which were new last year. I think adding coverage for them to our courses will help everyone understand the syntax.

Environment, specifically, is the way to work with EnvironmentValues. We’ll be working on more coverage of it, specifically, this summer!

1 Like

Hi!. I’ve gone through this tutorial twice now and I’m getting an error that says "…TaskList[1805:182654] [Assert] View <(null):0x0> does not conform to UITextInput protocol**

Any ideas on what this could be. The sheet is functioning as normal but the value is not being saved to my taskstore

Are you seeing that with the materials uploaded for this episode? If so, I can check it out, but I’d recommend waiting for the new version of this course, coming out this week.