From the course: Complete Guide to SwiftUI

Unlock this course with a free trial

Join today to access over 24,700 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: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 one we just used here and pop this open and we can see it right here. Okay, so that's the code we're talking about. And we've got this ID thing, the ID parameter in the for each consult, 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 is this VAR ID and it's set up to be a unique value. So we've got this unique value ID so…

Contents