0% found this document useful (0 votes)
181 views20 pages

Ios Interview and Questions

The document provides a comprehensive list of interview questions and answers related to iOS development, covering topics such as ARC, data types in Objective-C, concurrency, app states, and design patterns. It also discusses Swift features, JSON handling, and key concepts like MVC, protocols, and completion handlers. The content serves as a valuable resource for preparing for iOS developer interviews.

Uploaded by

krishhna.ios
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
181 views20 pages

Ios Interview and Questions

The document provides a comprehensive list of interview questions and answers related to iOS development, covering topics such as ARC, data types in Objective-C, concurrency, app states, and design patterns. It also discusses Swift features, JSON handling, and key concepts like MVC, protocols, and completion handlers. The content serves as a valuable resource for preparing for iOS developer interviews.

Uploaded by

krishhna.ios
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

IOS INTERVIEW AND QUESTIONS

1. What is ARC ?
ARC (Automatic Reference Counting) is a compiler-level feature that defines the
process of managing the lifetime of objects in objective-C.

2. Define Bundle ID ?
It uniquely defines every iOS application. A bundle identifier can recognize any
update to your app.

3. Name some imp data types found in Objective-C ?


Bool, CGFloat, NSinteger, NSstring

4. Define Cocoa/Cocoa touch ? Difference bewteen them ?


It is used for building software codes to run on iOS for iPhone. Cocoa Touch is
written in the objective-C language and is the result of combining the Foundation
and AppKit frameworks, while Cocoa is the result of combining the Foundation
and UIKit frameworks.

5. What are the methods to achieve concurrency? What is Concurrency?


Dispatch Queues, Threads, Operation Queues. On iOS devices, concurrency is
commonly used to allow you to run tasks such as downloading or processing data
in the background while keeping your user interface sensitive. Concurrency is a
fancy term for “running several tasks at the same time.”

6. When app is said to be not running the state?


It is said when it is not launched or gets terminated by the system while running.

7. Explain object?
Objects are mainly the variables that are of class types. It can be a function,
method, data structure, or variable.

8. When would you say that an app is in an active state?


An app is said to be in an active state when it is accepting events and running in
the foreground.

9. Which framework is used to construct app UI?


UIKIT framework. It renders drawing models, windows, event handling, UI, App
structure, Graphics, printing and views.

10. Explain layer objects in Swift ?


In Swift, layer objects are data objects representing visual content on UIView.
Views use layer objects to render their content. We can add custom layer objects
to the interface to implement complex animations and more.
11. What is GCD?
GCD (Grand Central Dispatch) defines as a library that offers object-based and
low-level API to execute tasks accordingly when managing threads. It will assist
you in increasing the responsiveness of your app. allows you to manage multiple
concurrent operations by using concurrency model than locks and threads to deal
with.

12. Mention the features of iOS 14


New App Library, Home Screen redesign, Translate app, No full-screen calls

13. What is Code Coverage ?


Code coverage is used to calculate the value of our unit tests.

14. What is Operator Overloading ?


Operator overloading is used to work on how existing operators perform with
types that already exist. Operators are those little symbols like +, *, and /.

15. Design Patterns in iOS


Design patterns are used to solve common problems in software design. They’re
models for writing code that’s simple to comprehend and reuse.. Look at some
common Cocoa design patterns:
Creational: Singleton.
Behavioral: Observer, and, Memento
Structural: Decorator, Adapter, Facade

16. What is the difference between assign and retain keywords?


The assign keyword is used to create a reference from one object to another
without increasing the source’s retain count. It assigns the directly to the instance
variable and does not copy or retain it. The retain keyword is used to create a
reference from one object to another. It increases the retain count of the source
object.

17. Which JSON framework does iOS support?


iOS supports the SBJson framework. SBJson offers flexible APIs and additional
control so that handling JSON becomes easier.

18. Mention Realm benefits ?


Open-source DB framework, from Scratch, Fast.

19. What is Enumeration or Enum ?


A class type containing a group of related items under the same umbrella, but it is
impossible to create an instance of it. For instance, the day of the week can only
be one of the following: Monday, Tuesday, Wednesday, Thursday, Friday,
Saturday, or Sunday. It is declared in a class and its values are accessed through
the instance members of that class.
20. What is the lazy property in swift?
.A property is considered lazy stored if its initial value isn't determined until the
first time it's utilized. By adding the lazy modifier before only a stored property's
declaration, you may indicate a property as a lazy stored property.

21. What are 3 benefits of guard statement?


There are no nested if let statements. An early exit out of the function using
return or using break. Guard statement safely unwrap optionals. Execution will
unquestionably depart the current scope if the condition is false (or, at the very
least, skip this iteration of a loop, break out of a loop, return from the current
block/function, or terminate the entire program). A GUARD statement is used to
transfer the program control out of the scope when one or more conditions are
not met.

22. Difference between ‘app ID’ and ‘bundle ID’ ?


The bundle ID is specified in Xcode, and it defines each App. App ID is used to
identify one or more apps from a single development team. It is a two-part string
with a period(.) separating Team ID and bundle IF search string. The bundle ID
search string is supplied by the developer, while Apple supplies the Team ID.

23. From where should UIKit classes be used ?


UIKit classes should be used from the application’s main thread only.

24. When an app is launched, what are its state transitions like?
Before launch, an app is not said to be running. After a brief transition through
the inactive state, it moves to the background or the active state when it is
launched.
Eg:- applicationDidBecomeActive()
applicationDidEnterBackground()
applicationWillEnterForeground()
applicationWillTerminate()

25. What is the use of application:willFinishLaunchingWithOptions and


application:didFinishLaunchingWithOptions?
Both of these methods are present in [Link] file and are used to add
functionality to the App when the App is going to be launched.

26. Three rendering options for JSONSerialization


The rendering options are:
MutableLeaves: are created as variable strings’ instances.
allowFragments: are not array or dictionaries’ instances.
MutableContainers: Dictionaries and arrays are not constants but variable
objects.
27. What is tuple in swift ?
A temporary container for multiple values is called a tuple. It is a list comma-
separated type and is enclosed in parentheses. It is an ordered list of elements.
There are two ways of accessing the object data in a tuple i.e. by name or by
position.

28. What is meant by QOS in app development?


QOS stands for Quality of Service. By assigning a QoS, you’re telling the system
how important it is, and the system prioritizes and schedules it accordingly.

29. What are essential certificates for issuing and developing apps in iOS?
Development Certificate & Distribution Certificate

30. Why is ‘reuseIdentifier’ used ?


The ‘reuseIdentifier’ is used to group all the similar rows from UITableView.
i.e., the rows that differ only in their content, otherwise having similar layouts. A
UITableView will normally allocate just enough UITableViewCell objects to
display the content visible in the table.

31. How can you reduce size of the App?


Bit-code, On-demand Resource, App Slicing

32. What is the difference between retaining and copy ?


Retaining an object means increasing the retain count by one. The instance of the
object is kept in memory till its retain count drops to zero. A reference to the
instance is stored, and the same is shared with anyone who retained it. At the
same time, copy means that the object will be cloned with duplicated value, but it
cannot be shared with anyone else.

33. Which lifecycle method of View-Controller used to load data from


remote server to display in the view ?
It is dependent on the data’s use case. If data is static and is not likely to change,
it can be loaded in viewDidLoad(Its called when loaded into memory) and
cached. Whereas, if data changes regularly, use viewDidAppear(called when
view is visible and presented on device) to load it. You can perform any layout
functions or draw n the UI.
34. What is a protocol, and how to define it?
A protocol defines a blueprint of properties, methods, and other requirements that
are suitable for a particular task. It describes how the type conforming to it must
behave. you can make e.g. a class conform to a protocol. In its simplest form, the
protocol is an interface that describes some methods and properties. The protocol
is just described as the properties or methods skeleton instead of implementation.
Properties and methods implementation can be done by defining enumerations,
functions, and classes.

Protocols are declared after the structure, enumeration or class type names. A
single and multiple protocol declaration can be possible. Multiple protocols are
separated by commas.

35. What is MVC? Its implementation in iOS ?


Its a design pattern that defines how logic will be separated when the user
interface is implemented. In iOS, UIView is the base class provided by Apple for
all views, and UIViewController is provided to support the Controller, which
listens to events in a View and updates it when data changes.A model is where
the data is stored.

MVC builds on top of the OOP’s concepts. It structures the flow of data and
interaction in our app. Many iOS frameworks, like UIKit, Cocoa Touch, use the
MVC pattern for messaging and structured data flow. Model-View-Controller is
used to pass the data from one part of our app to another.

What is a Responder chain?


A ResponderChain is a hierarchy of objects that have the chance of responding to
the received events.

36. What is singleton pattern ? What is called singleton class?


Its a design pattern that ensures only one instance exists for a given class and that
instance has a global access point. When needed for the first time, it generally
uses lazy loading to create a single instance. When only one instance of a class is
created in the application, that class is called a singleton class.

37. What is meant by ‘defer’ keyword ?


The ‘defer’ keyword provides a block of code executed in cases when execution
leaves the current scope.
38. What are properties in iOS?
Values are connected to certain classes, structures, or enumerations called
properties. Unlike computed properties, which calculate (rather than save) a
value, stored properties save constant and variable values in an instance.
Enumerations, classes, and structures all offer computed properties. However,
only classes and structures offer stored properties.

39. Difference between asynchronous and synchronous calls ?


Synchronous API calls won't continue to run until the API returns a response,
which the user may experience as latency or performance lag. However,
synchronous API calls can be advantageous if your app functions only once the
API response has been received.
Asynchronous calls don't pause (or wait) for the server to respond to the API
call. Your program continues to run, and a "callback" function is then called
when the server responds to the call.

40. Difference between strong and weak references in Obj-C ?


As long as you reference any object you assign to this property with a strong
reference, the compiler will take precautions to prevent its destruction. The
object won't be destroyed until you set the attribute to nil (unless one or more
other objects also hold a strong reference to it). called strong references
With a weak reference, however, you indicate that you don’t wish to be in charge
of the object's lifetime. Why? Because at least one other object has a strong
reference to the item you are weakly referencing. The object is destroyed when
that's no longer the case, and your weak property is then set to zero by default.

41. What are different app states in iOS ?


Not running, Inactive, Active, Background, Suspended.

Difference between iOS and Android?


iOS - for Apple devices(iPhones, iPads), Safari(default browser), Closed-source
Developed in C, C++,Swift & Obj-C
Android - for Android devices(smartphones), Google Chrome(default browser),
Open-source, Developed in C & C++

42. Can you explain completion handlers?


Completion handlers are functions used as parameters to pass to another
function. They are primarily tasked with handling asynchronous event responses.
In addition, completion handlers provide applications with information about an
operation’s completion.
Suppose you perform a time-consuming task, such as a network request, and you
want to do something immediately after the request completes. But you
definitely don’t want to waste resources by checking multiple times if the process
is ongoing or not. This is where completion handlers are used. A completion
handler is a closure that “calls you back” as soon as the time-consuming process
completes. They are closures in action.
43. What is JSON?
Simple data structures and objects are represented using JSON, a text-based,
human-readable data transfer standard in web browser-based programs, as well
as sometimes client-side and server-side programming environments. You can
serialize objects, arrays, numbers, characters, booleans, and null with JSON
syntax.
44. What are UI Elements in iOS?
The visual elements that we can see in our applications are known as UI
elements. Some of these components, such as buttons and text fields, respond to
user interactions, while others, such as images and labels, provide information..
45. What is an NSError in Swift?
The NSError class is a Cocoa class. The knowledge about an error condition is
encapsulated in an extendable, object-oriented manner by an NSError object.
46. Which is the state an app reaches briefly on its way to being suspended?
An app enters background state briefly on its way to being suspended.
47. Explain how you define variables in Swift language ?
Variables and constants must be declared before they are used. You announce
constants with the let keyword and variables with the var keyword.
48. What is the significance of “?” in swift?
The question mark makes a property optional if declared. The property may hold
a value or not. In case the property does not hold a value, the “?” helps in
avoiding runtime errors. This is useful in optional chaining
49. Mention what are types of integer does swift have?
Swift provides unsigned and signed integers in 8, 16, 32 and 64 bit forms
50. Mention what is Floating point numbers and its types in swift?
Floating numbers are numbers with a fractional component, like 3.25169 and -
238.21. There are two signed floating point number.
Double - a 64 bit floating point number, it’s used when values must be very large
Float - a 32 bit floating point number, it’s used when values doesn’t need 64 bit
precision

51. Explain multiple line and single line comment in swift?


Multiple line comment can be written as forward-slash followed by an asterisk
(/*) and end with an asterisk followed by a forward slash (*/).
Single-line comments are started with double slashes (//).
52. What is a de-initializer ?
A de-initializer is declared immediately before a class instance is de-allocated.
You write de-initializer with the deinit keyword. De-initializer is written without
any parenthesis, and it does not take any parameters. Its the method of
deallocating or cleaning up unused class instance objects in order to free up
memory space used by machine resources for better memory management.
53. Mention collection-types available in Swift?
In Swift, collection types come in three varieties Array, Sets and Dictionary.
Arrays is an ordered collection of values, which is stored in the same type of
values in an ordered list.
Sets are an unordered collection of unique values, which are stored in a distinct
value of the same type in a collection without any defined ordering.
Dictionaries are an unordered collection of Key and value pair associations in an
unordered manner.
54. What are control transfer statements used in Swift?
Using these can transfer the control of the program from one statement to
another without any conditions.
Continue, Break, Fallthrough, Return, Throw.
55. What is optional chaining ?
A process of querying and calling properties. Multiple queries can be chained
together, and if any link in the chain is nil then, the entire chain [Link] nil is
encountered at any point in the above chain, the app won’t crash — instead,
a nil is returned.
56. How base-class is defined in Swift?
In Swift the classes are not inherited from the base class and the classes that you
define without specifying its superclass, automatically becomes the base-class.

57. Mention characteristics of Switch in Swift?


When a case is matched in switch, the program exists from the switch case and
does not continue checking next cases. So you don’t need to explicitly break out
the switch at the end of case. Switch statement must be exhaustive, which means
that you have to cover all possible values for your variable. There is no
fallthrough in switch statements and therefore break is not required. This are used
as a substitute for the long if-else-if statements. Also supports any type of data,
synchronizes them and also checks for equality.

58. What are Half Open Range operators in Swift?


Specifies a range between two values a and b (a<b) where b is not included. It is
known as half open range operator because it contains its first value only not the
final value.

59. What are functions in Swift?


Functions are the set of codes used to perform specific task. Allows Common
behaviour at most places using code re-usability. A function makes it possible to
define reusable blocks of code. A function can perform a task that’s part of your
program. Usually, functions take some values that they can work with.

60. What is Nested Function in Swift?


A function inside a function is called a nested function.
61. Regular Expression in Swift?
Regular expressions are the special string patterns that specify how to perform a
search through a string.

65. Explain Dictionary in Swift?


Dictionary is used to store the key-value pairs and access the value by using the
key. It is just like hash tables in other programming languages. Dictionaries are
an association of an unordered collection of key-value pairs. Each value is
associated with a unique key

62. What is the use of break statement in Swift?


The break statement is used within a loop where you have to immediately
terminate a statement. It is also used to terminate a case in switch statement.

63. What is the use of continue statement in Swift loop?


The continue statement is used in Swift loop to change execution from its normal
sequence. It stops currently executing statement and starts again at the beginning
of the next iteration through the loop.

64. What is Inheritance in Swift?


Inheritance is a process in which a class can inherit properties, methods and other
characteristics from another class. Inheritance is supported in Swift programming
language. There are two types of classes in Inheritance in Swift: The class which
inherits the properties from other class is called child class or sub class.. The
main class from where the subclass inherits the properties is known as parent
class or super class.

65. What are the different ways to specify layout of elements in UIView?
Here are a few common ways to specify the layout of elements in UIView: Using
InterfaceBuilder, we can add a XIB file to our project, layout elements within it,
and then load XIB in our application code, also using InterfaceBuilder, we can
create a storyboard for our application.. We can create CGRects describing the
exact coordinates for each element and pass them to UIView’s (id)initWithFrame:
(CGRect)frame method.

66. What is SpriteKit and SceneKit ?


SpriteKit is a platform for creating animated 2D objects quickly and easily.
SceneKit is a platform for 3D graphics rendering

67. Difference between frame and bound ?


A UIView’s bounds are a rectangle with a size (width, height) and position (x,y)
relative to its own coordinate system (0,0).
A UIView’s frame is a rectangle with a scale (width, height) and position (x,y)
relative to the superview it is located within.
68. What is meant by deadlock ?
A deadlock is a situation that occurs when at least two threads are locked on a
different resource, and both are waiting for the other resource to finish its job.
And no one is able to unlock the resource it is guarding.
69. What is difference between strong, weak, read-only and copy?
Strong: Through the life of the object, the reference count will be increased and
the reference will be maintained

Weak: It can be said as a non-strong reference that means it refers to the fact that
we are referring to an object but not adding to its reference count. It’s often used
to establish a parent-child relationship. The parent has a strong connection with
the infant, but the child has only a small connection with the parent.

Read-only: Initially, The property will be set and it can’t be changed.

Copy: It means that when an object is created, we’re copying its value. Also
prevents its value from changing.

70. Does Obj-C contain private methods


No, there is nothing called a private method in Object-C programming. If a
method is defined in .m only, then it becomes protected; if it is defined in .h, it is
public.
71. What is a plist ?
PLIST stands for Property List. PLIST is basically a dictionary of value and keys
that can be stored in our file system with a .plist file extension. The property list
is used as a portable and lightweight means to store a lesser amount of data. They
are normally written in XML. Different types of plist are Binary and XML
Property List.
72. What is an abstract class in Cocoa ?
Cocoa doesn’t provide anything called abstract. It can create a class abstract that
gets checked only at the runtime while it is not checked at the compile time.

73. Mention Swift pattern matching techniques


Tuple, Wildcard, Optional, Expression, Type-Casting patterns

74. How is memory management handled in iOS?


Important in iOS applications due to memory and other [Link] leaks
and system crashes are all too common in iOS apps due to poor memory
management. 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.

75. Where we can test apple iPhone apps if we don’t have an iOS device?
If we don’t have an iOS device, we can test our application on simulators
provided by Apple on the Mac system.

76. Is Swift an OOP’s language? Yes


77. What type of objects are basic data types in swift?
Swift uses a standard set of basic data types for different purposes such as
Boolean values, numbers, and strings. Int, Double & Float(decimal numbers),
Bool(T/F), String(“”), Arrays and Dictionaries

78. What is init() in Swift ?


Initializers are also called to create a new instance of a particular type. An
initializer is an instance method with no parameters. Using the initializer, we can
write the init keyword. It is a process of preparing an instance of an enumeration,
structure or class for use.

79. How to add an element into an array?


Arrays are one of the most used data types in an application (app). We use arrays
to organize our application (app) data.. Array elements are simply surrounded by
a comma and the list of values is separated with square brackets.

80. What is a delegate in swift?


Delegate is a design pattern, which is used to pass the data or communication
between structs or classes. Delegate allows sending a message from one object to
another object when a specific event happens and is used for handling table view
and collection view events. Delegates have one to one relationship and one to
one communication.
81. What is the use of double question mark “??” in swift?
The double question mark “??” is a nil-coalescing operator, it is mainly a
shorthand for the ternary conditional operator where we used to test for nil. A
double question mark is also used to provide a default value for a variable.

82. What is the difference between Array and NSArray?


An array can hold only one type of data, whereas NSArray can hold different
types of [Link] array is a value type, whereas NSArray is an immutable
reference type.

83. What is the difference between class and structure?


Classes are reference types, whereas structs are value types. Classes can be built
on other classes have an inheritance, whereas struct cannot inherit from another
struct cannot have an inheritance. In class, we can create an instance with “let”
keywords and attempt to mutate its property, whereas there is no Mutability in
Structs. Classes have Type Casting, whereas struct doesn’t have Type Casting.

84. How to pass data between view controllers ?


1. Using Segue, in prepareForSegue method (Forward).
2. Setting the variable directly (Backword).
3. Using Delegate (Backword).

85. Who calls the main function of our app during app launch cycle?
The main thread calls the main function of our app. During the app launching
cycle, the system will create a main thread for the app and call the app main
function on that main thread.

86. Which is the superclass of all view controller objects?


UIViewController class is the superclass of all the view controller objects. The
functionality for presenting them, loading views, rotating them is a response to
the device rotations. All the standard system behavior is provided by the
UIViewController class.

87. What are source items used by xcode?


Framework, Source Group, Source File, Source Folder

88. What are different ways to pass data in swift?


There are several ways to pass data in swift such as KVO, Delegate,
NSNotification & Callbacks.

89. Explain usage of class and benefits of inheritance?


Subclass provides reuse interface, Modularity, provides mechanism for
customization.
90. Mention common features of Protocols & Superclass.
Reuse of Interface/Implementation, Supports modular design, Provides point for
customization.

91. Mention biggest changes in UserNotifications?


 Allows adding images, audio, and videos.
 Allows creating custom interfaces for notifications.
 Allows managing the notifications with interface in the notification center.

92. What is Optional chaining?


In this process, we may try to retrieve a value from a chain of the optional values.
If the optional contains a value, then calling the subscript, method or property of
an optional will return a value. If the optional is nil, then calling the subscript,
method or property of an optional will return nil.
An advantage of “optional chaining” in Swift is that programmers can create
multiple queries together. The entire chain of queries will fail if any of them
returns a “nil”. Swift allows developers to handle such failures effectively too.

93. What is Optional binding?


Optional Binding concept is used to find out whether an optional contains a
value, and it makes that value available as a variable or temporary constant. We
use an optional binding concept to check if the optional contains a value or not.
Optional binding can be used with the condition (if and while) statements to
check for a value inside an optional.

94. What are higher-order functions in swift?


 Map: Transform the array contents.
 Reduce: Reduce the values in the collection to a single value.
 Sort: Sorting the arrays.
 Filter: Transform the array contents.

95. Mention various ways to unwrap an optional in swift?


 Guard statement: safe.
 Forced unwrapping: using “!” operator, unsafe.
 Optional binding: safe.
 Optional pattern: safe.
 Nil coalescing operator: safe.
 Implicitly unwrapped variable declaration: unsafe in many cases.
 Optional chaining: safe.

96. What mechanism does iOS support for multi-threading?


 NSThread: It can create a low-level thread which can be started by using
the “start” method.
 NSOperationQueue: It allows a pool of threads to be created and is used to
execute “NSOperations” in parallel.

97. Explain key-points of Core Data


Core data is used for handling the model layer object in our applications. We can
treat Core Data as a framework to filter, modify, save, track the data within the
iOS apps. Core Data is not a relational database. Using core data, we can easily
map the objects in our app to the table records in the database without knowing
any SQL. Core data is the M in MVC structure.

98. Explain GCD in detail?


It is a low-level API for managing the concurrent operations. This concept is
used to help in improving application performance. This process is used to
manage multiple tasks at the same time. Grand Central Dispatch (GCD) is the
most useful API for multitasking with Async and Sync programming in iOS.

 Dispatch Queue: The Dispatch Queue manages the task in FIFO(First In


First Out) order. Dispatch queues are thread-safe as we can access them
from multiple threads simultaneously.
 Concurrent: This process has started multiple tasks at the same time but is
not sure of the termination at the same time. It can be finished in any order.
They execute one or more tasks at the same time concurrently. The task is
completed according to the complexity, and not by the order in the queue.
 Serial: Only one task will execute at a time. It can be used to synchronize
access to a specific resource.
 Sync: A synchronous function has return control to the caller after the task
is complete.
 Async: An asynchronous function returns immediately, by ordering the task
to start but will not wait for it to complete.

99. Explain use of inout parameter


By default, function parameters are constants. A good use case is a swap
[Link] 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.
An inout parameter allows you to change the value of a parameter inside the
function. To make a parameter in-out, use the inout keyword in front of the
parameter type. To pass a variable as an in-out, use & in front of its name.
100. Explain difference between equality(==) and identity operators(===)
The equality operator or == compares two values and checks if the two values
are the same or equal. Identity operator or === checks if the two references
point to the same instance (or same memory address). The identity operator
returns false when comparing two references to different object instances, even
if the two instances have the same value.

101. Why does “unwrapping” an “optional” in swift have importance?


For a regular string, the “count” property will show the number of letters in the
string. An “optional” string can just be “nil” though. It doesn’t contain
anything, therefore, it won’t have a “count”. By its very design, Swift doesn’t
allow such unsafe programming practices.
This is where Swift programmers use “unwrapping”. This process enables
programs to look inside the “optional”.
E. g., a Swift developer can use the “if let” syntax. This “unwraps” an optional
and provides the count of letters if there’s any value at all. You can use the
“else” condition to display a message of your choice if the “optional” string
contains “nil”. That also promotes safe programming.
One has several ways to “unwrap” an “optional”, however, some of them
aren’t very safe. E.g., “forced unwrapping” and declaring “implicitly
unwrapped” variables can often be unsafe.

102. Which one among “nil” and “.none” should you use in swift?
Experienced Swift developers recommend using “nil”. Having said that, “nil”
and “.none” work in the same way in Swift. “.none” is the short form of
“[Link]”. It does exactly what “nil” does. The common convention
among Swift developers is to use “nil”.

103. How is defining a constant in swift differ from than in Obj-C ?


While declaring Objective-C, a “const” is a variable used, whereas in swift “let”
keyword is used to create constants.

104. How to handle runtime errors in Swift?


Developers can create a custom “Error” type. They can use an enumeration
that conforms to the Swift error protocol.
Developers can add the “throws” keyword in the definition of a function or an
initializer. This would propagate the error from the function to the piece of
code that calls the function.
Functions with a “throws” keyword should have a “try” statement since such
functions might have errors. A “try” statement should reside within a “do-
catch” for it to execute.
Swift allows programmers to code “try” with a question mark, i.e., “try?”.
This will cause the return value of the “throwable” function to be “optional”. If
the function throws an error, the value will be “nil”. Otherwise, it will be the
wrapped return value of the function.

105. Is it possible to give default value to function parameter ? Yes


106. For a swift “enum”, how do “raw values” differ from “associated
values” ?
Developers use “raw values” to associate constants to “enum” cases. Swift
doesn’t allow duplicate values, and each “enum” case must have a unique
value.
Programmers can use the “rawValue” property to convert the value of an
“enum” to its raw value. On the other hand, they can use a dedicated initializer
to convert a raw value to an “enum” instance.
Developers can use “associated values” to associate data to an “enum” case.
These cases can have zero or more such values. Swift developers need to use a
“tuple” in the case definition.

107. How to resolve a circular reference in swift?


A circular reference involves two instances holding a strong reference to each
other. This causes a memory leak. That’s because neither of the 2 instances
will be deallocated. Developers need to replace one of the strong references
with a “weak” reference. They can also use an “unowned” reference. These
methods will enable them to resolve a circular reference.

108. Difference between atomic and nonatomic synthesized properties?


Atomic properties always return a fully initialized object. However, it comes at
the cost of performance. If there is a property that you know has no risk on
initializing value, then set it to nonatomic can gain a bit of performance.

Atomic: Default behaviour, Not fast, process entirely completed by CPU


Nonatomic: Not default behaviour, Faster, Not able to deal with multiple request
at the same time.

109. What do generics serve in swift?


It allows you to combine multiple functions into one function, furthermore,
you can prevent variable types-related errors. This allows you to achieve more
by coding less. 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 allows you to write flexible and reusable code that can work with any
data type. Imagine you’re writing a 3D vector structure, but you want to be able
to create vectors using integers, floats, and doubles. You definitely don’t want to
write the same code for each data type separately. This is where you can use
generics. For example, you can create a generic type for parameters (to represent
any type) using a letter e.g. T

110. How to parse JSON in swift?


The Swift “Decodable” protocol can decode JSON. Swift automatically
converts every type that conforms to this protocol. Programmers don’t need to
define each property that comes with a JSON, furthermore, the
“JSONDecoder” in Swift can handle “optionals”. Developers can decode
JSON arrays too.

111. What are Cocoa and Cocoa Touch?

112. Difference between thread and process?


113. List down 3 ways to append two arrays in swift?
Using the method "append(contentsOf: )" , Using the "+=" operator ,
Appending two arrays by using the "+" operator and adding the result to a new
array

114. What are the common features in Swift structures and swift classes?
Swift Structs and Swift classes can both define attributes for storing values and
[Link] init, both structures and classes in Swift can create initializers to
set up their initial state (). They can be extended using extensions.

115. What is the use of “mutating” keyword in ios swift?


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. we will need to create a mutating function to update
the value inside the structure.

116. Expain Protocol vs class in ios swift?


A protocol, in its most basic form, explains what an unknown sort of object can
accomplish. It has two or three different sorts of properties, as well as
procedures. Protocol never includes anything inside the methods, nor does it
provide actual storage for the properties. You can build extensions to your
protocols that give default implementations of the methods in a more advanced
form. However, you are still unable to provide storage for properties.

Classes are tangible objects. They are not needed to embrace protocols, which
means they do not have to implement the required attributes and methods.
Classes can be used to generate objects, whereas protocols are simply typed
declarations. Consider protocols to be abstract definitions, whereas classes and
structs are actual objects that can be created.

117. When set is more preferable than array in ios swift?


You only want to add each item once. Duplicates are never permitted in sets.
The order of the items in the collection is irrelevant to you.

118. Use of “self” in a 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

119. Difference between Self and self in ios swift?


Self with a capital S refers to any type that follows the protocol. Because Int
conforms to SquareInteger() 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.

120. What are the Several methods for unwrapping an optional ?


 Forced unwrapping - (Optional Chaining)
 Nil coalescing operator
 Optional pattern - An optional pattern matches items wrapped in an
Optional<Wrapped> enumeration's some(Wrapped) case.
 Guard Statement -
 Optional Binding -
 Implicitly unwrapped variable declaration -

121. How to disallow a Class from being Inherited?


By making the class a final class by using the final keyword.

122. Difference between Functions and Methods ?


There is a small difference between a function and a method. Both are reusable
chunks of code, however, methods belong to classes, structures, or enumerations
but functions don’t.

123. Benefits of Higher-Order Functions


They provide flexibility & sometimes improve the quality of code and make it
shorter and concise.
124. Fileprivate vs Private ?
 A fileprivate property can be read anywhere in the same Swift file but not
outside of it.
 A private property can only be read inside the type in which it was declared
(as well as in the extensions of that type in the same file).
125. What is Force Unwrapping? When should you use It ?
Force unwrapping tries to convert an optional to a value regardless of it contains
a value or not.. Force unwrapping is unsafe because if the optional is nil and you
try to unwrap it, it triggers an error that crashes the app. Thus, it should be
avoided unless you’re 100% sure the optional is not nil.
126. What are Extensions ?
In Swift, you can use extensions to add functionality to an existing type. you can
create an extension by using the extension keyword.
127. What is the Pounds Property known as ?
The pounds property is also known as a computed property. In Swift, computed
properties are not stored in the object. A computed property means that its value
gets computed “on-demand” only when trying to access it.
128. What is Swift Message ?
Swift Messages is a library used to display messages as a status bar at the top or
at the bottom of the iOS device’s screen.

You might also like