InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What do you understand about Grand Central Dispatch (GDC)? |
|
Answer» GCD (Grand Central Dispatch) is a low-level API for controlling several operations at the same TIME. This notion is employed to aid in the enhancement of APPLICATION performance. This procedure is used to handle numerous jobs at once. The most relevant API for multitasking with Async and Sync programming in iOS is Grand Central Dispatch (GCD).
|
|
| 2. |
What is a Swift module? |
|
Answer» A single unit of code distribution in IOS Swift is REFERRED to as a module. The Swift "import" KEYWORD can be used to import a framework or application that has been created and shipped as a single unit. In Swift, each Xcode build target is treated as an INDEPENDENT module. An example of using the "import" keyword is given below: import UIKit |
|
| 3. |
What are the several methods for unwrapping an optional in Swift? |
|
Answer» The several methods for unwrapping an optional in Swift are as follows:
|
|
| 4. |
State your understanding of core data. |
|
Answer» Apple's Core Data framework is one of the most POWERFUL frameworks for macOS and iOS programmes. In our applications, core data is used to manage the model layer object. Within iOS applications, we may USE Core Data as a framework to FILTER, alter, save, and track data. Core Data is not a relational database in the traditional sense. Without learning SQL, we can easily connect the objects in our APP to the table records in the database using core data. The M in the MVC structure STANDS for core data. Some features of Core data are listed below:
|
|
| 5. |
In Swift, how would you describe a circular reference? What are your options for resolving it? |
|
Answer» When two instances have a strong connection to one other, a circular REFERENCE occurs, resulting in a memory leak because neither of the two instances will ever be deallocated. The reason for this is that you can't deallocate an INSTANCE if it has a strong reference to it, yet each instance maintains the other alive due to the strong reference. This might LEAD to a deadlock which is EXTREMELY bad for the application. Breaking the strong circular reference by replacing one of the strong references with a weak or unowned reference would fix the problem of a circular reference. |
|
| 6. |
What are a few scenarios in which we can't avoid using implicitly unwrapped optionals and why so? |
|
Answer» The FOLLOWING are the most prevalent reasons for using implicitly unwrapped optionals:
|
|
| 7. |
What do you understand about optionals in ios Swift? What is the problem which they solve? |
|
Answer» An optional, in ios Swift, allows any type of variable to reflect a lack of value. The absence of value in Objective C is only available in reference types that use the nil special value. This is not possible with value types like int or float. With optionals, ios Swift EXTENDS the absence of value ideas to both reference and value types. An optional variable can be set to either a value or nil, which indicates that it has no value. An EXAMPLE of an optional is GIVEN below: var text: String?text = "I will GO to school."print(text) |
|
| 8. |
What do you understand about generics in ios Swift? |
|
Answer» Generics are a way to avoid code duplication. It is USUAL to repeat a method that takes one type of parameter to accommodate a parameter of a different type. Generics can be used in both functions and data types in Swift, such as classes, structures, and enumerations. func integerEquality(_ a: Int, _ b: Int) -> Bool { RETURN a == b}func stringEquality(_ a: String, _ b: String) -> Bool { return a == b}stringEquality("hello", "hello") // returns trueintegerEquality(5, 5) // returns trueFor example, the second function in the above code is a "clone" of the first, but it accepts texts rather than numbers. func commonEquality<T: Equatable>(_ a: T, _ b: T) -> Bool { return a == b}commonEquality("hello", "hello") // returns truecommonEquality(5, 5) // returns trueYou can consolidate the two functions into one and maintain type SAFETY at the same time by using generics. Given above is the way to do it in general. Because you are testing equality here, you can USE any type that implements the Equatable protocol as a parameter. This code achieves the desired outcome while preventing the use of non-typed parameters. |
|
| 9. |
What is the meaning of a GUARD statement? What are the advantages of using Swift's GUARD statement? |
|
Answer» When one or more conditions are not met, a GUARD statement is used to TRANSFER PROGRAM control out of the scope. This remark AIDS in AVOIDING the doomsday pyramid. The following is the syntax of a GUARD statement: guard condition else{Statements} |
|
| 10. |
How can the double question mark symbol "??" be used in ios Swift programming? |
|
Answer» The nil-coalescing operator "??" is a SHORTHAND for the ternary conditional operator, which we used to test for nil. A double question MARK can also be used to set a variable's default value. "default STRING" stringVar?? This does PRECISELY what you would EXPECT: if stringVar is not nil, it is returned; otherwise, the "default string" is returned. |
|
| 11. |
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} |
|
| 12. |
Explain the difference between Self and self in ios Swift. |
|
Answer» There is a distinction between Self (CAPITAL S) and self (small S) when WRITING protocols and protocol EXTENSIONS. When USED with a capital S, Self refers to the protocol COMPLIANT type, such as String or Int. When used with a lowercase S, self refers to the value contained within that type, such as "hi" or 999, for instance. Consider the following SquareInteger extension as an example: extension SquareInteger { func squareANumber() -> Self { return self * self }}Remember that Self with a capital S refers to any type that follows the protocol. Because Int conforms to SquareInteger in the example above, when called on Int, the method returns an Int. Self with a lowercase S, on the other hand, refers to the type's current value. If the preceding example were run on an Int containing the value 4, the result would be 4 * 4. |
|
| 13. |
How can we use the "inout" parameter in ios Swift? Explain with an example. |
|
Answer» By default, function parameters are constants. CHANGING the value of a function parameter from within the function's body causes a compile-time error. Modifying the local variable also modifies the passed in arguments, which is KNOWN as the "inout" parameter. The passed-in arguments will have the same value if it is not present. Trying to remember the reference type while using inout and the value type when not using it. The SWAP function, which modifies the parameters handed in, is an excellent example. Consider REDUCING the copying overhead as well. If you have a function that takes a memory-intensive large value type as an argument (say, a huge structure type) and returns the same type, and the function return is only used to replace the caller argument, the inout parameter is the associated function parameter to use. As we can see in the example given below, a CALL to the function "demoFunction" copies arguments to function property 'aBigStruct'(copy 1) and the function property is mutated after which, the function returns a copy of the mutated property to the caller (copy 2). However, in the function "demoFunctionWithLessCopyOverhead", call by reference is being done and zero value copy overhead is there because of the usage of inout optimization. struct demoStruct { private var counter: Int = 1 // ... a lot of stored properties mutating func incrementCounter() { counter += 1 }}/* call to this function copies argument to function property 'aBigStruct'(copy 1) function property is mutated function returns a copy of mutated property to caller (copy 2) */func demoFunction(var aBigStruct: MyStruct) -> MyStruct { aBigStruct.incrementCounter() return aBigStruct}/* call by reference -> zero value copy overhead because of the inout optimization */func demoFunctionWithLessCopyOverhead(inout aBigStruct: MyStruct) { aBigStruct.incrementCounter()}var ex = MyStruct()ex = demoFunction(ex) // copy, copy: overheaddemoFunctionWithLessCopyOverhead(&ex) // call by reference: no memory reallocation |
|
| 14. |
Show the use of "self" in a method using an example. |
|
Answer» In Swift, the self property of an instance is a special property that holds the instance itself. In most cases, self appears in a class, structure, or ENUMERATION's initializer or method. The most common use of self is in initializers when you are likely to WANT parameter names that match your TYPE's property names, such as this: struct student { var myName: STRING var myFriend: String init(myName: String, myFriend: String) { print("\(name) is being ENROLLED in class...") self.myName = myName self.myFriend = myFriend }} |
|
| 15. |
When is the usage of a set more preferable than an array in ios Swift? |
|
Answer» If all of the following conditions are met, you should use a set rather than an array:
|
|
| 16. |
How should one consider the usage of strong, weak and unowned references? |
|
Answer» ASK yourself, "Am I dealing with REFERENCE types?" to see if you need to worry about strong, weak, or unowned. If you are working with Structs or Enums, ARC is not in charge of memory management, so you do not have to worry about defining weak or unowned constants or variables. In hierarchical relationships, strong references are acceptable when the parent REFERS to the child, but not when the child refers to the parent. Strong references are, in fact, the most appropriate type of reference the majority of the time. If two instances are optionally linked, make sure ONE of them has a weak reference to the other. When two instances are linked to the point where one cannot exist without the other, the instance with the OBLIGATORY dependency must keep an unowned reference to the other instance. |
|
| 17. |
Explain Protocol Vs Class in ios Swift. |
Answer»
|
|
| 18. |
ASCII Legacy Property ListQuestion: What do you understand about training closure syntax in ios Swift? |
|
Answer» Many iOS Swift functions accept MULTIPLE parameters, the last of which is a closure. Trailing closure syntax is a small amount of syntactic sugar that makes READING and writing common CODE easier. For example, CONSIDER the following code snippet: FUNC RunClosureAfterGreeting(name: String, closure: () -> ()) { print("Hi, \(name)!!!") closure()}Instead of the above code snippet, we can write the following code (which is way cleaner than the previous one): RunClosureAfterGreeting(name: "Sonia") { print("The closure has been run")} |
|
| 19. |
What do you understand about PLIST in ios? List some examples of types of PLIST. |
|
Answer» The abbreviation PLIST in ios stands for Property List. PLIST is a value and key dictionary that can be saved in our file system using the .plist file EXTENSION. The property list is used to store a smaller quantity of data in a portable and lightweight MANNER. In most CASES, they are written in XML. The following are examples of several sorts of property lists:
|
|