Answers for "make optional protocol swift"

0

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")
    }
}
Posted by: Guest on May-03-2022

Code answers related to "Swift"

Browse Popular Code Answers by Language