mercredi 24 août 2022

How to use specific functions in specific classes that are all declared inside one protocol in swift?

I have a protocol declared in one class say 'Class MainClass', that protocol has 2 functions, e.g.:

protocol Test {
    func Cat()
    func Dog()
}

In Class A, I am implementing both the methods from the protocol eg:

Class A: Test {
func Cat(){
   print("I am cat")
}

func Dog{
  print("I am dog")
}

}

,but inside Class B I want to implement only Cat(). Xcode is not allowing me to add only one function from the Test protocol. How do I implement only one function from the same protocol, I dont want to create another protocol that has only Cat() in it. Please help. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire