Technical ios interview questions for experienced swift : Part 2
Swift interview Question for ios developer
21What design patterns are commonly used in iOS apps?
Ans: Typical commonly used patterns when building iOS applications are those that Apple advocates for in their Cocoa, Cocoa Touch, Objective-C, and Swift documentation. These are the patterns that every iOS developer learns. They include MVC, Singleton, Delegate, and Observer.
MVC
Singleton
Delegate
Observer
22.Does singleton allows multiple instance?
No singleton does not allow multiple instance
23. What is Completion Handler?
A completion handler is the function basically used to get the parameter .it notify the completion of process .it is used to return the value . it is basically used in network call session.
2 types of completion handler :
1. Asynchronous : task execution is done at same time
2. Synchronous: task execution is one after the another
24. What are properties and types of properties?
Properties are the object which are associated with Struct, classes and enums
There are two types of properties
- Stored Properties
- Computed Properties
Stored Properties are the variable which are stored at the instant of class or Struct
struct classStrength {
var girls: Int
let boys: Int
}
var totol = classStrength(girls: 0, boys: 3)
Computer Properties are the variable which performs the getter and setter functionality
struct classStrength {
var girls: Int
let boys: Int
var total:Int {
get {
return boys + girls
}
set(total) {
boys + girls
}
}
}
var totol = classStrength(girls: 0, boys: 3
25.What is Struct in Swift?
Struct is the value type object, it is the member-wise initialiser. it is called as value type because it passes the value to the function, when u use the struct whole thing is duplicated.it points the value of the object. it shows he value of the object
Defining a Struct
struct School {
var clothes: String
var shoes: String
}
26. What is Class in swift ?
Class is the reference type of object. it passes the reference data to the function . when class is used each object points to the same original object if you change one they all will change. it show the reference of the real object
class School {
var clothes: String
var shoes: String
}
27.What is difference between frame and bound ?
frame changes parent view layout .bound changes only child view layout
28. What is tuple?
Tuple is the used function to return multiple value it may be of different datatype. Tuple is the value type object
func split(name: String) -> (firstName: String, lastName: String) {
let split = name.components(separatedBy: " ")
return (split[0], split[1])
}
29. Whats is higher order function?
Higher order functions are simply functions that operate on other functions by either taking a function as an argument, or returning a function
30 .What is inheritance?
A Capacity of the class to derive property or characteristic from another class
here SomeSuperclass is the parent class and someSubClass is the child class
example :
class SomeSuperclass {
// baseclass definition goes here
}
class SomeSubclass: SomeSuperclass {
// subclass definition goes here
}
31. What is singleton class in swift ?
SingleTon class is the object which provide single point of access to the function of the class
example:
final 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
32. What are the feature only available in class compare to struct in swift?
* Type Casting : We can check the type of the class in runtime.
* Reference Counting : Allow more than 1 reference to the class instance
* Inheritance : A class can inherit the property or characteristic of other class but in struct we cannot.
* De initialisation : we can de-initialise the class resource at any instant.
33 . What is optional Chaining?
Optional Chaining is the Process of querying and calling the properties with an optional that may be nil
let object = {}
object?.data = 1
Please comment for more interview Question for iOS swift interview questions
34. What is difference between Array and NSArray?
- Array can have one data type were as NSArray can have multiple Data Type .
- Array is pass by Value were as NSArray is the pass by Reference.
- Array is mutable were as NSArray is immutable
35. What are the Execution State in iOS Application or Application Life Cycle?
- Not Running
- Suspended
- Active
- InActive
- Background
36. What is Optional Binding ?
Optional Binding is the process of check the object contains the value or not.
example :
var data: String? = nil
if let value = data {
print(value)
}
37. What are the various Ways of of unwrapping the optional value in Swift ?
- if let statement
- guard let statement
- Optional chaining
- Force unwrapping
- Unwrapping using higher order function
- Nil coalescing operator
38. What are the different types of ViewController Life Cycle?
- ViewDidLoad
- ViewWillAppear
- ViewWillDisappear
- ViewDidAppear
- ViewDidDisappear
- ViewwillLayoutSubView
- ViewDidLayoutSubView
39.What is difference between ViewDidLoad and ViewWillAppear?
ViewDidLoad is called once in ViewController life cycle it is called when view is loaded.
ViewWillAppear is called before view is visible. this method is used to change the viewLayout before view is visible.
40. What are the Control type statement in swift ?
break , continue , Return and failthrough
41.What is difference between frame and bound ?
frame changes parent view layout .bound changes only child view layout
In the context of Swift programming and UI development, “frame” and “bounds” refer to two different properties associated with UIViews (user interface elements like buttons, labels, etc.) that are used to describe their position and size within their parent view or superview.
-
Frame: The
frame
property of a UIView represents the view’s position and size in its parent view’s coordinate system. It’s a CGRect (Core Graphics Rectangle) that defines the view’s position (origin) and dimensions (width and height) with respect to the parent view’s top-left corner. Changing the frame property of a view will alter its position and size on the screen. However, it’s important to note that changes to the frame property can also affect the view’s layout and the layout of its subviews.
let myView = UIView(frame: CGRect(x: 50, y: 100, width: 200, height: 150))
-
Bounds: The
bounds
property of a UIView represents the view’s internal coordinate system. It’s a CGRect that defines the view’s dimensions (width and height) within its own coordinate space, with its origin (0,0) always being at the top-left corner of the view. Changing the bounds property does not affect the view’s position within its superview; rather, it can be used to scale, translate, or transform the view’s content within its own coordinate system.
Example:
let myView = UIView(frame: CGRect(x: 50, y: 100, width: 200, height: 150))
myView.bounds = CGRect(x: 0, y: 0, width: 300, height: 200)
In summary:
-
frame
: Represents the view’s position and size within its parent view’s coordinate system. Changing this property affects the view’s layout within its superview. -
bounds
: Represents the view’s dimensions and coordinate system in its own space. Changing this property doesn’t affect the view’s position within its superview, but it can transform the view’s content within its own coordinate system.
Understanding the distinction between these properties is crucial when working with UIViews in Swift to create responsive and visually appealing user interfaces.