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 protocols in ios Swift? |
|
Answer» The PROTOCOL is a concept that is similar to a Java interface and is a highly common component of the Swift programming language. A protocol is a set of attributes, methods, and other requirements that are appropriate for a specific activity. The protocol, in its most basic form, is an interface that describes some methods and characteristics. Instead of implementation, the protocol is described as a skeleton of properties or methods. Enumerations, functions, and classes can be used to implement properties and methods. After the structure, ENUMERATION, or class type names, protocols are declared. It is possible to declare both a single and several protocols. COMMAS are used to separate multiple protocols. A protocol can be defined in a similar way to STRUCTURES, enumerations, and classes: Protocol demoProtocol{// the protocol definition will be GOING at this place}Multiple protocols can be defined by separating them using commas: Class demoClass: demoSuperclass, protocolOne, protocolTwo{// the Structure definition will be going at this place} |
|
| 2. |
What is the use of the "mutating" keyword in ios Swift? |
|
Answer» Ios SWIFT structs are immutable since they are of the value type. Other variables, for example, cannot modify the values of structure at any point in time. Only the "mutating" keyword is necessary to change the values of SELF variables within the FUNCTION of the structure. Let us take the following CODE snippet for example: struct demoStruct { var foo: String = "Initial String" func transformString() { foo = "Transformed String". //The above results in a compile time error: Cannot assign to property: 'self' is immutable. //We need to MARK the method 'mutating' to make 'self' mutable. }}We get a compile-time error when we try to alter the value of variable "foo" inside a function declared in the struct itself. As a result, we will need to create a mutating function to update the value inside the structure. As a result, the correct code is: struct demoStruct { var foo: String = "Initial String" mutating func transformString() { foo = "Transformed String". }} |
|
| 3. |
Name the JSON framework which is supported by iOS. |
|
Answer» iOS supports the SBJson framework. The SBJson framework adds more CONTROL and flexibility to the JSON handling process. It is a well DESIGNED and extremely adaptable framework that ALLOWS APIs (Application Programming Interfaces) to function in a variety of WAYS. SBJSON is one of the many open-source JSON parsers or generators created with Objective-C. These allow you to use JSON easily when coding Objective-C apps. |
|
| 4. |
What are some features that Swift classes can support but Swift structs cannot? |
|
Answer» Given below are some FEATURES which Swift classes can support but Swift structs cannot:
|
|
| 5. |
What are some common features in Swift structures and Swift classes? |
|
Answer» Some common features in Swift structures and Swift classes are as follows:
|
|
| 6. |
State the control transfer statements present in ios Swift. |
|
Answer» The control transfer statements present in ios Swift are as FOLLOWS:
|
|
| 7. |
In Swift, what does the init() method do? |
|
Answer» The process of preparing an instance of an enumeration, structure, or class for use is known as initialization. Initializers are also used when a new instance of a type is created. An initializer is a no PARAMETER instance method. The init keyword can be WRITTEN using the initializer. Their PRIMARY ROLE is to ensure that new instances of a type are correctly initialized before they’re used for the first time. Its syntax is given below: init(){// New Instances are initialized here} |
|
| 8. |
In iOS Swift, what types of objects are considered basic data types? |
|
Answer» For various purposes, Swift uses a common set of basic data types such as Boolean values, integers, and strings:
|
|
| 9. |
Explain the various steps (or execution states) involved in the development of an ios Swift application. |
|
Answer» The various steps (or execution states) involved in the development of an ios SWIFT application are as follows:
|
|
| 10. |
List down three ways in which we can append two arrays in ios Swift. |
|
Answer» Let US consider that the two arrays are DECLARED as FOLLOWS: var firstArray = ["Sonal", "RAHUL"]let secondArray = ["Nawaz", "Riya"]A thing to be noted is that the first ARRAY has been kept mutable so we can append the second array to it. The three ways in which we can append the second array to the first one are as follows:
|
|
| 11. |
Throw light on some of the differences between Swift and Objective C. |
||||||||||||||||||
|
Answer» Some of the DIFFERENCES between ios Swift and Objective C are as follows:
|
|||||||||||||||||||
| 12. |
What is the difference between the "==" operator and the "===" operator in ios Swift? |
|
Answer» The fundamental difference between the "==" operator and the "===" operator in ios Swift is that the equal to "==" operator compares value types to see if the values are the same while the equivalent to "===" operator compares reference types to see if the references point to the same instance (both point to the same memory address) or not. Let us consider the following example for understanding the difference between the two in a better way: class Human: Equatable { let id: Int let nameOfPerson: String init(id: Int, nameOfPerson: String) { self.id = id self.nameOfPerson = nameOfPerson } static func == (left: Human, RIGHT: Human) -> BOOL { return left.id == right.id }}let human1 = Human(id: 2, nameOfPerson: "JANVI")let human2 = Human(id: 2, nameOfPerson: "Janvi")Now, for the piece of code given below, we can say that the two human instances are equal since their id is the same. Therefore, "Equal Instances!" gets printed. if human1 == human2 { PRINT("Equal Instances!")}else{ print("Instances Not Equal!")}Now, for the piece of code given below, we can say that the two human instances are not equivalent even though their id is the same since they point to different areas in the Heap Area, that is, they point to different ADDRESSES. Therefore, "Instances are not Equivalent!" gets printed. if human1 === human2 { print("Equivalent Instances!")}else{ print("Instances are not Equivalent!")} |
|
| 13. |
Highlight the key difference between Upcast and Downcast in ios Swift. |
|
Answer» The key difference between UPCAST and Downcast in ios SWIFT is that upcasting from a derived to a base CLASS can be verified at compile-time and will never fail to compile and Downcasts, on the other HAND, can fail to compile since the precise class is not always KNOWN. It is possible that the UIView you have is a UITableView or a UIButton. |
|
| 14. |
How is memory management done in iOS Swift? |
|
Answer» Automatic Reference Counting is used by Swift (ARC) in order to do memory management. This is the same thing in Swift as it is in OBJECTIVE C in terms of notion. When you assign or unassign instances of classes (reference types) to constants, properties, and variables, ARC keeps track of STRONG REFERENCES to those instances and increases or decreases their reference COUNT correspondingly. It frees up memory consumed by objects with a reference count of zero. Because value types are copied when assigned, ARC does not raise or DECREASE its reference count. If you don't declare differently, all references will be strong references by default. |
|
| 15. |
List some advantages and disadvantages of using ios Swift. |
|
Answer» Some advantages of using ios Swift are as follows:
Some disadvantages of using ios Swift are as follows:
|
|