1.

State your understanding of delegates in ios Swift.

Answer»

Delegate, in ios Swift, is a design pattern that allows data or communication to be passed across structs or classes. Delegate allows one object to deliver a message to ANOTHER when a certain event occurs, and it is used to handle table and collection view events. Delegates have a one on one INTERACTION and communicate with one another. 

An example of a delegate is given below:

// Defining a custom delegate known as SeeActionDelegateprotocol SeeActionDelegate { // Defining the required delegate variables var state: GetState { get } var userIdentity: String? { get set } // Defining the required delegate BLOCKS var errorHandler: ((Error) -> Void)? { get set } // Defining the required delegate functions func handle(action: GetAction)}

The enums used in the above delegate are:

enum GetState { CASE `default` case loading}enum GetAction { case saved case canceled}


Discussion

No Comment Found