make optional protocol swift
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")
}
}