Google News
logo
Swift Interview Questions
Optional Binding concept is used to find out whether an optional contains a value, and it makes that value available as a variable or temporary constant. We use an optional binding concept to check if the optional contains a value or not.
 
Optional binding can be used with the condition (if and while) statements to check for a value inside an optional.
UIViewController class is the superclass of all the view controller objects. The functionality for presenting them, loading views, rotating them is a response to the device rotations. All the standard system behavior is provided by the UIViewController class.
MVC stands for the model view controller. MVC is a powerful software architecture pattern for using developing apps.
 
MVC builds on top of the Object-Oriented Programming concepts. It structures the flow of data and interaction in our app. Model-View-Controller is an important fundamental concept to be understood in iOS development. Many iOS frameworks, like UIKit, Cocoa Touch, use the MVC pattern for messaging and structured data flow.
 
Model-View-Controller is used to pass the data from one part of our app to another.
 
Its a design pattern used to assign objects in an application in any one of the three roles :
 
Model : Model is a wrapper of data. Model is a representation of our app data and it holds the information to a specific user like birthdate, username, etc. The model manages the application state. This also includes writing and reading data. The Model encapsulates an individual set of data and applies some logic to manipulate that data.

View : View is a representation of a UI(User Interface). A View is an object that the visible to the user and it interacts with a user interface (UI).

Controller : Controller is an intermediary between the View and the Model. The controller controls all the logic that goes between the Model and the View. Its inter-communicates messages between the Model and the View, and vice versa.
A completion handler in Swift is a function that calls back when a task completes. This is why it is also called a callback function.
 
A callback function is passed as an argument into another function. When this function completes running a task, it executes the callback function.
 
Example :
Here is a demonstrative (but not useful) example of using a completion handler in Swift:
func greet(_ completion: () -> ()) {
    print("Hello world!")
    completion()
}
greet({
  print("Task finished.")
})
 
Output :
Hello world!
Task finished.