Presentation
on Protocols
Shibbir Hossain
100864497
Protocols
- Blueprint
- suits particular task or functionality
- implemented by class, structure, enums
Similar reference
- Interface in Java
- Abstract class
Syntax of Protocol
protocol SampleProtocol
{
// protocol definition goes here
}
- Multiple protocols can be intialized just by commas
struct SampleStructure: MyProtocol, NewProtocol {
// structure intialization goes here
}
Property requirements
- prefixed with
var keyword - gettable and settable properties
-
writing { get set } after type declaration
- protocol SampleProtocol {
var mustBeSettable: Int { get set }
var doesNotNeedToBeSettable: Int { get }
}
-
Code snippet
protocol items {
var type:String{get}
var name:String{get}
var phoneNumber:String{get}
}
class Person:items{
var type:String
var name:String
var phoneNumber:String
init(type: String, name : String, phoneNumber: String) {
self.type = type
self.name = name
self.phoneNumber = phoneNumber
}
Project
https://bodyguardapp.com.au
Presentation
By Shibbir Hossain
Presentation
- 518