Posts

Showing posts with the label Swift Interview Questions

Higher Order Functions - Swift Programming

HigherOrder Functions Introduction Sort Map Reduce Filter Introduction: What is Function? Functions  are self-contained chunks of code that perform a specific task.  Function  name should give clarity that what it does, and that name is used to “call” the function to perform its task when needed. Every function in Swift has a type, consisting of the function’s parameter types and return type. You can use this type like any other type in Swift, which makes it easy to pass functions as parameters to other functions, and to return functions from functions.  Functions can also be written within other functions to encapsulate useful functionality within a nested function scope. If the entire body of the function is a single expression, the function implicitly returns that expression. What is HigherOrder Function? A higher order function is a function that accepts one or more functions as an input (or) returns a value of function type as output (or) doing both Passing Func...

DispatchGroup - Multiple API Calls - Swift Programming

DispatchGroup: You attach multiple work items to a group and schedule them for asynchronous execution on the same queue or different queues. When all work items finish executing, the group executes its completion handler.   You can also wait synchronously for all tasks in the group to finish executing.   DispatchGroup instance - Creates a new group to which you can assign block objects.   Functions: enter() - Explicitly indicates that a block has entered the group. wait() - Waits synchronously for the previously submitted work to finish. Can also used with TimeOut option- DispatchTime - Gives DispatchTimeoutResult leave() - Explicitly indicates that a block in the group finished executing. notify() - Schedules the submission of a block with the specified attributes to a queue when all tasks in the current group have finished executing. Can be used with & without QOS import  UIKit public typealias CompletionHandlerWithBoolStatus = ( _ status: Bool ) -...

Enumeration - Swift Programming

Enum Introduction Raw Values Associated Values CaseIterable Hashable Recursive Enumeration Introduction: An enumeration defines a common type for a group of related values and enables you to work with those values in a type-safe way within your code.   Enumerations in Swift are much more flexible, and don’t have to provide a value for each case of the enumeration.   Swift enumeration cases don’t have an integer value set by default, unlike languages like C and Objective-C. Enum cases don’t implicitly equal 0, 1, 2 and 3. Instead, the different enumeration cases are values in their own right, with an explicitly defined type of Enum Defined. Enumerations in Swift are first-class types. They adopt many features traditionally supported only by classes, such as 1. computed properties to provide additional information about the enumeration’s current value, and 2. instance methods to provide functionality related to the values the enumeration represents. Enumerations can also define ...