I see everywhere in iOS programming that delegate is used….I am not sure what for is being used.
Can you please explain me about it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When you need objects to behave differently from each other, you can either give them different implementations (often by subclassing, as is done with
UIViewController), or by delegation. The difference is that polymorphism in the first case is achieved by making the objects of different type, whereas in the second, polymorphism is achieved by making objects of the same type delegate certain bits of functionality to objects of arbitrary type.The reason people like delegation so much is that it allows a much cleaner class hierarchy: you don’t need to subclass every little thing, just to respond to a few hooks. That’s why we use delegation.
If you want to know the mechanics of delegation, and how to do it in your own classes, you’re welcome to see my article Using custom delegates in Objective-C.