Technical swift interview Question and Answer for iOS developer: Part 3
iOS interview Questions swift and Answer for experience and fresher candidate
iOS interview questions swift for experience student for preparation of job interview
1 .What is ARC (Automatic Reference Count ) ?
ARC ( Automatic Reference Count ) is the used to manage and track the memory in iOS Application . It Automatically manage the application memory and release the class memory when it is no longer needed.
2.What is difference between Foundation and Core Foundation?
Core Foundation
is the C-level API, which provides CFString, CFDictionary and the like.
Foundation
is Objective-C, which provides NSString, NSDictionary, etc.
3.How many states are there in iOS life cycle?
- Not running
- Active
- Inactive
- Suspended
- Background
4. In Which thread does Api gets called?
In background Thread Api services gets call
Ex URLSession.shared.dataTask
5. What is singleton class in swift ?
SingleTon class is the object which provide single point of access to the function of the class
example:
class Common {
static let shared = Common()
private init()
func sum()-> Int {
return 10 + 20
}
}
accessing the singleton
let Sum = Common.shared.sum()
print (Sum)
output Sum = 30
6.What are the difference between Cocoa and Cocoa Touch ?
FrameWork
- Cocoa is the combination of Foundation and Appkit
- Cocoa touch is the combination of Foundation and UIKit
OS
- Cocoa is basically related to MAC OS
- Cocoa touch is related to all the Devices of the Apple
API
- Cocoa: All the classes used in Cocoa have the NS prefix Ex: NSTextField
- Cocoa Touch: classes used in Cocoa have the UI prefix Ex: UITextField
7. What is the use of reuseIdentifier in swift ?
ReuseIdentifier is used to group the cell of the UItableview.
8. What are the Different types of DisPatchQueue?
Main , concurrency and Serial
9. What is KV0 ?
KVO(Key value observer) is used to detect the changes in property or value.
10 . What is Lazy Property in swift ?
A lazy stored property is a property whose initial value is not calculated until the first time it is used. You indicate a lazy stored property by writing the lazy
modifier before its declaration. iOS interview Question and Answer : Part 3 for more iOS interview Questions swift and Answer
11. What is difference between override and overload?
overloading : When two or more method in the same class have same name but different parameter its called overloading
override : when the method (name and parameter) are the same in the super class and the child class. its called override
12.What are the design pattern used in swift?
There are 3 types of design pattern used in swift
- Creational: Creational design patterns are a subset of design patterns in software engineering that deal with the process of object creation. These patterns provide solutions to the problem of how to instantiate objects in a flexible and efficient manner, while promoting good design principles and reducing coupling between components.
- Structural :Structural design patterns in software engineering focus on how classes and objects are structured to form larger components and systems. These patterns help in composing classes and objects to create more flexible, maintainable, and efficient code. Here are some common structural design patterns in Swift:
- Behaviour:Behavioral design patterns in software engineering deal with the interactions and responsibilities of objects and classes, focusing on how they communicate and collaborate to fulfill certain tasks or responsibilities. These patterns help manage the behavior and communication between objects in a more organized and flexible way. Here are some common behavioral design patterns:
13: How could we get device token ?
Ans: There are two steps to get device token. First, we must show the user’s permission screen, after we can register for remote notifications. If these steps go well, the system will provide device token. If we uninstall or reinstall the app, the device token would change.
14: What format code is used to print a formatted message with NSString?
Ans: You would use the following:
NSLog(@”Message == %@”,msg);
15. What is Dependency injection ?
Dependency Injection is the software design pattern in which object receives other instance that it depends on.
16 What is a protocol, how do you define your own, and when is it used?
Ans: Protocols are a way to specify a set of methods you want a class to implement if it wants to work with one of your classes. Delegates and data sources such as UITableViewDelegate and UITableViewDataSource are indeed protocols.
17: What is your process for tracing and fixing a memory leak?
Ans: The best approach to this question is to provide the candidate with an existing project and a known memory leak and ask him/her to debug it.
18: What are “strong” and “weak” references? Why are they important,and how can they be used to help control memory management and avoid memory leaks?
Ans: A strong reference is one that occurs by default anytime that a variable is being created. There is an important property with reciprocal strong references, and it is that when this happens, a retain cycle occurs. In this situation, ARC will never be able to destroy the objects. This is described as being a memory leak.
These types of reciprocal and strong references should always be avoided. When this is not possible, using weak references can come to the rescue. If one of these references is declared as weak, the retain cycle will be broken, and, therefore, the memory leak will be avoided.
19: What is NSUserDefaults?
Ans: NSUserDefaults is a class that allows a developer to save settings, properties, and information that is related to the application or the user data. NSUserDefaults stores keys and their associated value. The following types can be stored with NSUserDefaults:
- NSData
- NSString
- NSNumber
- NSDate
- NSArray
- NSDictionary
In general, the candidate should be prompted to discuss the benefits and disadvantages of using NSUserDefaults as opposed to other storage types.
20 What is Auto Layout?
Ans: Auto Layout is a means by which developers can create user interfaces, by defining relationships between elements. It provides a flexible and powerful system that describes how views and the UI controls relate to each other. By using Auto Layout, you can get an incredible degree of control over layout, with a wide range of customization, and yield the perfect interface.