///what does protocol extension allows us to do in swift
///it allow to create default function for protocol
protocol Greeting {
func sayHello()
}
extension Greeting {
func sayHello() {
print("Hello World")
}
}
class SimpleGreeting: Greeting { //No need to impliment the function
}
class WishesGreeting: Greeting {
func sayHello() {
print("Hello World this is new year")
}
}
//Other way to create option protocol
@objc protocol ObjcGreeting {
@objc optional func sayHello()
}
class ObjcSimpleGreeting: ObjcGreeting { //No need to impliment the function
}
class ObjcWishesGreeting: ObjcGreeting {
func sayHello() {
print("Hello World this is new year")
}
}
class ProtocolOrientedProgrammingViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .white
let wishesGreeting = WishesGreeting();
wishesGreeting.sayHello()
}
}