From the course: Make SwiftUI Playgrounds Applications

Unlock this course with a free trial

Join today to access over 24,600 courses taught by industry experts.

Protocols, Hashable, and Identifiable

Protocols, Hashable, and Identifiable - Swift Tutorial

From the course: Make SwiftUI Playgrounds Applications

Protocols, Hashable, and Identifiable

- [Instructor] In the last lesson, we ended with an error due to this thing called hash. This brings us into the issues of protocols in general and the hashable and identifiable protocols more specifically. A protocol is a template for a class or struct. It contains declarations for properties or methods. A class or struct adopts the protocol then defines them more specifically for this situation. You are guaranteed that anything that adopts a protocol can be used the same as anything else that adopts a protocol. For example objects adopting the hash protocol require values to be of a simple type such as int or float or string. However, menu item is not a simple type. It's a combination of simple types to make the struct for each adopted hashable for the value of id. Therefore, you must use a simple type to make an id. And self is the struct menu item. So it causes an error. So let's go over and take a look at menu item.…

Contents