Meeting Protocols in Swift

Brian Advent
A free video tutorial from Brian Advent
Software developer, educator and mathematician
4.3 instructor rating • 6 courses • 8,484 students

Learn more from the full course

Using Advanced iOS Frameworks and Techniques with Swift 3

Learn and Master the Coolest iOS Frameworks and Techniques by Example

05:25:37 of on-demand video • Updated

  • leverage the power of multiple great frameworks like UIKit Dynamics or the Photos framework
  • use Xcode live rendering to improve productivity
  • deal with live photos
  • access Web API's efficiently and structure and display the received data
  • use UICollectionView to display information
  • use UIPresentationControllers and custom transitions
  • implement the peak and pop feature of 3D Touch
  • add Today Extensions and Widgets to your Apps
  • understand the concept of Protocol Oriented Programming and Value Types
  • use the concept of Protocol Oriented Programming together with UIKit
  • implement caching to reduce network traffic and loading times
  • use CocoaPods to enhance projects with 3rd party framworks
English [Auto] Before we go more into detail what protocol oriented programming can do for us and what makes it so powerful and swift. I like to talk about the practical basics first and later we're also going to see how we can use particle oriented programming in real work real world wide good apps. So let's talk about the basics. And if you aren't familiar with protocols they are a way of extending the functionality of an existing class or structure and a protocol can be thought of as a blueprint or an interface that defines a set of properties and functions and a class or structure that conforms to a protocol is required to fill out these properties and methods with values and implementations. And it is also possible to define some of those functions as optional but let's have a look at the very basics now first. So we can define a protocol by simply writing the protocol keyword giving it a name and I am going to name my protocol now Party and our party protocol will have a motto. So this is going to be a game. A property that we want to define. And now instead of defining a a value for that property we have to specify if we can get values and set values to that property and for our function that we want to define. I'm calling it welcome guest. There isn't a function body or method body. It's just the definition of the function that we have to write into a protocol. And now let's use a class that conforms to that protocol and I'm going to call that superhero party. And by setting a column here you can can make this class conform to a protocol. And now if we just have to look at that and wait a few seconds the compiler will immediately tell us that there is an error and the error is that the type superhero party does not conform to the protocol party. So to fix said this protocol requires the property Mottau and the proper and the protocol also requires the function welcome guest. So if we now implement that first of all the motto property let's maybe assign superhero here super hero and the function or let's just read welcome guests and we of course get all a completion for that since we did find it in the protocol and what we want to do here is simply print. Hi and welcome to this motto party. And then we can all merrily use this. This class by creating an instance of this type so we are having an event which is a superior party and then we can use it then. And welcome guest. So this is how you and of course get the console output for that. And this is how you can define protocols and how you can use protocols and in the next video we're going to see a in an example of how we can use protocols and much more how we can use protocol extensions to make our lives in swift a lot easier.