lundi 29 février 2016

What is the purpose of protocols in objective c or swift if all methods are optional (such as uitextfielddelegate)

So I just went through the pain of learning objective c and swift (it is actually been a great experience so far) and while I get what the purpose of protocols serve (to have a type conform to a set list of methods or/and properties), I don't understand what the purpose of a protocol with all optional methods.

if all methods are optional in a protocol, why would you conform to the protocol instead of just writing the functions from scratch in your class? I don't see what the benefit or purpose of conforming to the protocol is in this case.

Are the optional methods there just as suggestions of functionality that could be implemented? Thanks again for any help.

Aucun commentaire:

Enregistrer un commentaire