From the course: SwiftUI Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

The Identifiable protocol

The Identifiable protocol

- [Instructor] When I showed you for each earlier in this course, we got some errors that I resolved by using ID colon self. However, that doesn't always work. Let's explain why, and get rid of the ID parameter. So iterative views, like for each, want unique IDs for each item. So let's go over to find one here. Let's go over to order view, which is when we just used here. And, pop this open, and we can see it right here. Right? So that's the code we're talking about. And we've got this ID thing. The ID parameter in the for each can solve many of the simple cases as we've been looking at, if you do things like ranges and things like that. But, it fails when you get to more complex data. And I cheated here in our last video to get this to work right by using ID. So let's figure out why ID works, and what you can use instead of it. So over here in order item, if we go to the top here, you can see my struct. And, here…

Contents