@jessycatterwaul Thanks for your prompt response! You clarified a lot for me but I am still confused on my experiment to pass down a “task class” and edit it. When I do this in the “RowView.swift file” like so:
struct RowView: View {
var task: Task
var body: some View {
Button(action: { self.task.name = "This new name should be shown but is not!" }) {
Text(task.name).strikethrough(task.completed)
}
}
}
The new name is not updated in the list. It will be however, if I open the the NewTaskView, which forces a re-render.
I don’t understand how ObservedObject can listen to the appending of the array (without a binding), but cannot listen to the change of a reference type’s property in that array.
Are you using the 11.4 beta? That’s not the behavior I get. Only the new rows re-render.
In order to see what you’re seeing, I need to change the Identifiable behavior of Task. Again, this is all subject to change. Don’t put any faith in SwiftUI magically working, when there are ways to force it to work.
Arrays are value types. @Published is just a shortcut to calling objectWillChange in the array’s willSet observer (with some async magic to make it more like didSet).
I wouldn’t think that would result in anything different. You’re still using the same id. I don’t know what the rest of your project looks exactly like, though.
That’s why I mentioned above that Swift Arrays are value types. I didn’t realize that you didn’t know about what you found at that link, which is the converse of that. If you reassign a reference in an Array, that’s a mutation of the Array. But if you mutate any property of a reference in an Array, it’s not.
More on this here. Let me know if you think there’s anything missing that we don’t cover, which would have helped you. (I realize the third link is after this course, in the learning path.)
I’d like to see a video of this “weird fading”. As you can see in the comments for most of the videos, all of us are having an issue after adding a task, but I haven’t heard about fading yet!
I had the behavior in the simulator in my own app when using exactly your codes of the tutorial.
And here some error messages… maybe they help?
2020-04-27 21:06:07.117449+0200 TaskList[1439:62793] -[_UIRemoteKeyboards proxy]_block_invoke Failed to access remote service: Error Domain=NSCocoaErrorDomain Code=4099 “The connection to service on pid 1336 named com.apple.UIKit.KeyboardManagement.hosted was invalidated from this process.” UserInfo={NSDebugDescription=The connection to service on pid 1336 named com.apple.UIKit.KeyboardManagement.hosted was invalidated from this process.}
2020-04-27 21:06:07.126861+0200 TaskList[1439:57227] [Snapshotting] Snapshotting a view (0x7f8b36082600, UIKeyboardImpl) that is not in a visible window requires afterScreenUpdates:YES.
Ah! I never looked at it in the canvas preview. That doesn’t happen in the Simulator or on-device. But what does happen, as others have noticed, is probably worse.
Fatal error: Index out of range: file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1103.2.25.8/swift/stdlib/public/core/ContiguousArrayBuffer.swift, line 444
I’m not using the extension. I’m using the simpler method recommended in the comments.
So when we want to make our own apps, do we have to have those kinds of extensions in our project? I didnt quite understand what purpose those extensions played. Why did the errors go away?
I’m running into this same issue. Not sure what I’m doing wrong. I even download the materials and upload the files from the tracklist and still get this error. Any idea what could be wrong or how I can fix it to move on with the rest of the course.
I found this a little bit Hard to follow, I’m guessing it’s because of the newness of swiftUi and the fact that you needed to go into this alternative way of doing things. I’m just going to keep going and not let it put me off