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 - 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
-
-
-
(Locked)
More on the view hierarchy12m 11s
-
(Locked)
Formatted numbers8m 23s
-
(Locked)
Computed properties6m 7s
-
(Locked)
Arrays9m 54s
-
(Locked)
For loops9m 42s
-
(Locked)
Use ForEach in SwiftUI8m 32s
-
(Locked)
Protocols, Hashable, and Identifiable3m 56s
-
(Locked)
Importing models and assets8m 27s
-
(Locked)
Adapting models8m 43s
-
(Locked)
Scroll view and list6m 34s
-
Work with @State and toggle buttons8m 43s
-
(Locked)
Make Button arrays7m 13s
-
(Locked)
Work with @Binding5m 59s
-
(Locked)
Enumeration types8m 45s
-
(Locked)
Selection from lists4m 21s
-
(Locked)
Optional values6m 10s
-
(Locked)
-