In this blog I'll explain about delegation design pattern in iOS.
Delegation is design pattern in iOS where one class (called a delegator) give control or responsibility for some behaviour logic to another class (called delegator).
In Swift , delegation can be achieved by writing an abstraction layer called a Protocol.
Protocols are contracts , when an object (say a UIViewController) subclass agrees to providing logic back on recieving the message. (called confoming a protocol).
Delegation is use for one to one message passing and it's used often instead of subclassng a class to change its behaviour.
One main advantage of delegate over subclassing is that a class may implement multiple delegate protocols.
Data Source is often confused with Delegates the only difference between them is that the delegates supplies behaviour logic where as data source supllies data.
For Example :
UITableView itself doesn't know how many cells to present and what to present in each cell , it asks other class (i.e our custom class) to inform it about number of cells and what data cell to return.
Thanks,
Related Tags
More From Oodles
Mahipal Singh | 13-Dec-2024
Ready to innovate? Let's get in touch
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Varun Wadhwa
Varun is a mobile developer with experience in various technologies like Titanium , Cordova and native iOS development.