Join Károly Nyisztor for an in-depth discussion in this video Methods and class-bound protocols, part of Swift 4: Protocol-Oriented Programming.
- [Instructor] Protocols can also also…provide instance and type message requirements.…I add an instance method called update.…It takes an argument called data of type data.…And it returns a boolean.…I also add a static method called increment counter.…This method is supposed to implement the…internal counter property.…If we define a requirement for a method that…modifies the instance, it is recommended…to mark it with the mutated keyword.…
Since the update method is probably going…to modify the instance, let's mark it at mutating.…The mutating keyword allows value types to also…adopt the protocol.…Now if you want to restrict conforming types…to classes only, we can define the protocol as…such by making it inherit from the any object protocol.…Now we get the compiler error because of the mutating…keyword.…Class methods can always modify the class,…thus we don't need to use the mutating keyword…in class use.…
We should enforce reference semantics only…if protocol requirements should not be fulfilled…by a value types.…
- Comparing object-oriented programming with protocol-oriented programming
- Methods and class-bound protocols
- Adopting a protocol
- Declaring asynchronous behavior
- Preparing and implementing fallback logic
- Implementing an app using protocol-oriented programming
Skill Level Intermediate
1. Protocol-Oriented Programming
4. Implement the Weather App Using POP
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.