0% found this document useful (0 votes)
84 views

Interview Preparation IOS

The document discusses key differences between MVC and MVVM architectures, what protocols are in Swift and their uses, differences between stored and computed properties, and details on various types of initializers in Swift including designated, convenience, required, and more. It provides definitions and examples for each concept to help explain them clearly.

Uploaded by

mounika
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views

Interview Preparation IOS

The document discusses key differences between MVC and MVVM architectures, what protocols are in Swift and their uses, differences between stored and computed properties, and details on various types of initializers in Swift including designated, convenience, required, and more. It provides definitions and examples for each concept to help explain them clearly.

Uploaded by

mounika
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Interview Preparation

1. Difference between MVC and MVVM architectures


MVC - Model-View-Controller
MVVM - Model-View-ViewModel
MVC
Model - data resides
View - Layer is the face of our App
Controller - Its intermediate layer that handle the communication between view and model.
Contains all business logic and presentation logic
Disadvantages of MVC
1. Weak separation of concerns, Controller will handle everything like business logic,
presentation logic, updating UI and animation
2. Hard to unit test because controller is having all the logics including UIKit
3. Hard to maintain, when the project is growing the controller will be chaotic
MVVM
Model - Holds the data
View - Face of our App
ViewModel - Holds the business logic and binds the UI (data binding, bindData method in
Controller).
Advantages of MVVM
1. Provides better decoupling of UI and presentation logic. This decoupling results in
thin, flexible and easy-to-read viewcontroller classes in iOS
2. Communication between view and viewModel is done through Data binding
approach.
3. Easy to write unit testcases for the App
4. When you update the viewModel then UI will be automatically updated through
binding.

Architectures are for - Scalability, Reliability and Maintainability

2. What is protocol?
A protocol defines a blueprint of methods, properties and other requirements that suit a
particular task or piece of functionality. The protocol can be adopted by a class, struct or
enumeration to provide actual implementation of those requirements.

1. A class can adopt any number of protocols, but it can inherit only 1 superclass
2. Multiple inheritance for classes is not allowed in swift
3. Variable properties can be gettable or gettable and settable
4. Protocol must conform to a class, struct or enum to provide actual implementation.
5. Inside protocol definition method can have parameters and return types but not body.
6. Default values can’t be specified for method parameters within protocol definition.
7. A protocol can inherit one or more other protocols and can add other requirements
on top of the requirements it adopts.
8. In protocol extensions we can provide default implementations.
9. How protocol method can be made optional
3. Stored property vs Computed property
1. Stored properties store constant(let) and variable(var) values as a part of instance,
whereas Computed properties calculate a value.
2. Both are usually associated to instance of a particular type.
3. Properties which are associated to type itself are type properties
4. Stored properties of Constant Structure instances (If you create an instance of a
struct and assign that instance to constant, you cannot modify the instance
properties, even if they were declared as variable properties)
5. For Classes if you assign an instance to constant then it will allow to modify it’s
variable properties.
6. Lazy Stored Properties
a. A lazy Stored property is a property whose initial value isn’t calculated until
the first time it is used. You indicate a lazy stored property with lazy modifier
before it’s declaration.
b. Lazy property should be always declared as variable because its initial value
might not be retrieved until after instance initialization completes.
c. Constant properties must always have a value before initialization completes,
therefore they can’t be declared as lazy.
7. Computed properties don’t store a value. Instead, they provide a getter and a
optional setter to retrieve and set other properties and values indirectly.
8. For setter default we have newValue in computed property
9. Read only computed properties (Computed property with only have getter but no
setter)
10. Property Observers
a. Property observers observe and respond to the changes in a property’s value.
b. willSet is called just before the value is stored (default parameter will be
newValue)
c. didSet is called immediately after the newValue is stored (default parameter
will be oldValue)
d. Custom parameter
4. Convenience intializer vs designated intializer vs required intializer
Intialization is the process of creating an instance for a class, struct or enum for use.
1. Intializers are special methods that can be called to create a instance before they are
used for the first time.
2. Swift intializers do not return a value.
3. Instance of class types can also implement deintializer, which performs any custom
cleanup just before an instance of class is deallocated.
4. Classes and structures must set all their stored properties with an initial values
before the time of instance is created. They can’t be left in an indeterminate state.
5. Default property values during property declaration (Assign a default value to the
property during its declaration)
6. Initialization Parameters - are part of intializer definition. They have the same
capabilities and syntax as function and method parameters.
7. Initializers are identified based on the name and type parameters. Argument labels
should be provided otherwise it will lead to compile time errors.
8. Default intializers
a. Swift provides default initializers for classes or structs that provides default
values for all of its properties and doesn’t provide one intializer itself.
9. Memberwise intializers for Structures
a. Unlike default intializers structs receive a memberwise initializer, even if it has
stored properties that don’t have any default values.
b. When you call a memberwise initializer you can omit values for any properties
that have default values.
10. Initializer delegation for value types
a. Initializers can call other initializers to perform a part of an instance
initialization. Avoids duplicate code across multiple initializers
11. Class inheritance and Initialization
a. Designated initializers
i. Designated intializers are primary intializers for the class. A
designated initializer fully initialises all of the class stored properties
and calls an appropriate superclass initializer to continue initialization
process up the superclass chain.
ii. Designated initializers are funnel points through which initialization
takes place and through which the initialization process continues to
its superclass chain.
b. Convenience initializers
i. Convenience initializers are secondary, supporting initializers for the
class.
ii. You can define a convenience initializer to call a designated initializer
of the same class, as the convenience initializer can set some of the
designated initializers parameters to default values.
iii. You don’t have to provide convenience initializers if your class don’t
require them.
iv. Convenience initializers are written in the same style as designated
initializers but with the convenience modifier placed before the init
keyword separated by space.
c. A Designated initializer must call its immediate super class designated
initializer.
d. A Convenience initializer must ultimately call its designated initializer.
e. Two Phase Initialization
i. Each stored property is assigned with an initial value by the class that
introduced it.
ii. Once the initial state of stored property is determined then the second
phase starts. Each class is given the opportunity to customise its
stored properties further before the new instance is considered ready
for use.
iii. In Phase 2 customization will be done at superclass first and then to
subclass
f. Initializer Inheritance and Overriding
i. You will always write the override modifier when overriding a
superclass designated initializer, even if your subclass’s
implementation of the initializer is a convenience initializer.
g. Automatic Initializer Inheritance
i. Assume that you provide default values for all the stored properties in
subclass
1. If your subclass doesn’t define a designated initializer then it
will automatically inherit all of its super class designated
initializers.
2. A subclass can implement a superclass designated initializer
as a subclass convenience initializer as a part of satisfying rule
h. Failable initializers
i. After init keyword we will add a question mark and if there is a failure
we will simply return nil.
ii. These are introduced for numeric type conversions.
iii. A failable initializer can call its super class failable initializer
iv. You can override a failable initializer with non-failable initializer but not
the other way around.
i. Required initializers
i. Write the required modifier before the class initializer to indicate that
every subclass of the class must implement the initializer.
ii. You must write required modifier before every subclass
implementation of the required initializer to indicate that the initializer
requirement applies to further subclasses in the chain.
5. Extensions in Swift
Extensions add functionality to an existing class, struct, enum or protocol types.
This includes the ability to extend types for which you don’t have access to the original
source code.
1. Extensions can add computed instance properties and computed type properties to
existing types.
2. Computed properties are read-only in extensions. They can’t add stored properties.
3. Extensions can add convenience intializers to a class but not designated intializers.
Designated intializers and de-initializers must be provided in original class
implementation.
6. Memory Management in swift
iPhone has 2 ways of storing data - disk and RAM
1. When an app is run on your phone then a file containing all the executable
instructions will be loaded into RAM.
2. A chunk of RAM called heap. Where all the instances of a classes will live.
3. In Swift reference types are allocated in heap but not value types.
4. Memory management is handled by Automatic Reference Counting(ARC)
5. For every new instance there will be a reference count. Reference count 0 indicates
that particular instance is no longer needed. ARC will deallcoate memory for the
instance.
6. Strong, weak and unowned
a. Strong
b. Weak
c. unowned

7. ViewController Lifecycle
1. ViewDidLoad()
a. This method is called only once in the viewController Life cycle
b. Called when all the view are loaded
c. Network call, User Interface and other tasks which are need to be done only
once.
2. viewWillAppear()
a. This method is called everytime before the view is visible and before any
animation is configured.
b. View has bound but no orientation is set.
c. Override this method to perform custom tasks associated with displaying the
view such as hiding fields or disabling actions before the view is visible.
3. viewWillLayoutSubViews()
a. When view bounds change, the view adjusts the position of its subviews.
4. viewDidLayoutSubViews()
a. This method is called after the viewController has been adjusting to its
subview following a change on its bound.
b. Add code here to make changes to subviews after they have been set.
5. viewDidAppear()
a. This method is called after the view is present on the screen.
b. Usually save data to coredata or start Animation or start playing a video or
sound.
6. viewWillDisappear()
a. This method is called before the view is removed from the view hierarchy. The
View is still on the view hierarchy not removed yet.
b. Unload animations, handle times, hide the keyboard, cancelling network
requests, revert any changes to parent UI. Also this is an ideal place to store
state.
7. viewDidDisappear()
a. This method is called after the VC’s view has been removed from the View’s
hierarchy. Use this method to stop listening for notifications or device sensors.
8. Application Life Cycle
The main point of entry of iOS Apps is AppDelegate
1. AppDelegate is a protocol that your app has to implement to get notified about user
events such as app launch, app goes into background or foreground, app is
terminated, a push notification is opened etc.
2. willFinishLaunchingWithOptions
a. This method is intended for initial application setup. Storyboards have already
been loaded at this point but state restoration hasn’t occurred yet.
3. didFinishLaunchingWithOptions
a. This call back method is called when the application has finished launching
and restored state and can do the final initialization such as creating UI.
4. applicationWillEnterForeground
a. Called after didFinishLaunchingWithOptions or if your app becomes active
again after the phone call or other system interruption.
5. applicationDidBecomeActive
a. To finish up the transition to foreground
6. applicationWillResignActive
a. Is called when the app is about to become inactive(when the phone receives
a call or user clicks on home button)
7. applicationDidEnterBackground
a. Is called when your app enters background state after becoming inactive.
b. You will have approximately 5 seconds to run any tasks you need to back
things up incase the app gets terminated later or right after that.
8. applicationWillTerminate
a. Is called when your app is about to be purged from memory. Call any final
cleanup’s here.
9. Class vs Struct
10. Class method vs static method
11. Defer keyword

12. Multi threading


13. Service call in swift (URLSession and Alamofire)
14. Persistent storage (CoreData and Realm)
1. How to delete all the values in CoreData
2. In Realm how to update with new property without clearing the old data
3. How to achieve relationship between entities in CoreData
15. Framework vs Library
1. Library
a. A library is a set of methods that can be called. Each does some work and
returns the control to the client.
b. When you call a method from a library you own the control.
2. Framework
a. A framework embodies an abstract design, with more behaviour built-in.
b. In order to use it, you need to insert your behaviour into various places in the
framework.
c. Your code will be called by the framework.
d. With a framework control is inverted.
16. Class, Struct and Enum
1. Class
2. Struct
3. Enum
a. Enum defines a common type for a group of related values and enables you
to work with those values in a type-safe way within your code.
17. Optionals
Optionals will have 2 possible values, None or Some T. Where T is an associated value.
1. Force unwrapping(Exclamation mark)
2. Optional binding (if let & guard let)
3. Optional chaining (Used for structs & classes with ? operator for instance)
4. Nil Coalescing operator (??)
18. Push Notifications
There are 2 types of notifications in iOS
1. User Notification Framework and User Notification UI Framework
2. Notification Service App Extension was introduced that allows you to modify the
content of remote notification before they are delivered
3. Request Authorization in AppDelegate didFinishLaunchingWithOptions method.
4. User Notification Framework supports adding categories and actions to the
notifications.
5. Categories - Defines the types of notifications app supports and communicates to the
system how we want a notification to be presented.
6. Actions - Each category can have upto 4 actions associated with it. Actions are
basically custom buttons, that on tap dismiss the notification interface and forward
the selected action to the app for immediate handling.
1. Local Notifications
a. The app configures the notification details locally and pass those details to
the system. The system then handles the delivery of notifications when the
app is not in foreground.
2. Remote Notifications
a. You can use your’s company server to push data to user’s device via
APNs(Apple Push Notification Service)
b. Terminology
i. APNS(Apple Push Notification Service) - It is a cloud service that
allows approved third party apps installed on Apple devices to send
push notifications from remote server to the user over a secure
connection.
ii. Device token - An app specific token that is globally unique and
identifies one app-device combination. It enables communication
between Provider, APNs and device.
iii. Provider - Server that actually send remote notification including the
device token and other information to the APNs.
c. How remote notifications work
i. App registers with APNs
ii. APNs sends device token to the Device and then to the App.
iii. App sends this device token to the Provider.
iv. Provider will send notifications with that device token to APNs, which
then sends to Device, which then sends to the App.
d. Configurations
i. Enable remote notifications in Capabilities
ii. Register with Apple Push Notification Service(APNs) and receive a
app specific device token.
iii. Send the device token to notification server provider.
iv. Implement support for handling incoming remote notifications.
19. SwiftUI
20. Size classes
21. Storyboard and XIB
22. TableView methods order
23. CollectionView methods with order
24. GCD(Grand Central Dispatch)
25. DispatchQueue and DispatchGroup
1. Serial Queues and Concurrent Queues
2. Synchronous and Asynchronous
26. Identifiers
27. Navigation and data passing between controllers
Data passing can be done in 8 ways between Controllers
1. Segues (In Storyboards)
2. Delegate design
3. Singleton design
4. Assigning value to the property
5. Passing data through method parameters
6. NotificationCenter
7. Intializers
8. Using closures (completion block to pass data)
28. SSL pinning
29. Closures
Closures are self contained blocks of functionality that can be passed around and used in
our code
1. Passing closures as completion handlers is a common pattern in many API’s
2. Used for event handling and callbacks
3. Closures can capture and store references to any constants or variables from the
context in which they are defined.
4. We can pass closure as a parameter to a function.
5. Function vs closure
a. Function is declared using func keyword where as closure doesn’t have func
keyword
b. Function have always name but closure doesn’t have.
c. Function doesn’t have the in keyword whereas closure has in keyword
30. Higher order functions (map, flatMap, compactMap, filter, reduce, sorted)
31. Escaping and Non-Escaping closures
32. Memory leaks
33. Lazy keyword
34. CoreAnimation
35. LinkedList in Swift
1. Reverse a Single LinkedList
2. Sort Even and Odd Numbers in Linkedlist
36. Apple maps
1. MapKit for maps
2. CLLocation
3. MapView
4. MKCoordinateRegion (setRegion)
5. Annotations (MKAnnotation)
6. Which method is called for capturing location
37. Serials Queues, Concurrent Queues, global Queues and Operation Queues
1. Operation Queues
a. BlockOperation
b. We can add dependency between between tasks.
c. We can have control over the tasks.
38. Provisioning profile, Organization identifier, bundle identifier and p12 certificate
1. Provisioning profile
a. A provisioning profile is a collection of digital entities that uniquely ties
developers and devices to an authorised iPhone development team and
enables device to be used for testing.
b. Single device can contain multiple provisioning profiles
2. Bundle identifier
a. A bundle identifier uniquely identifies an application in Apple’s ecosystem
b. No 2 applications can have same bundle identifier
c. Apple encourages developers to use reverse domain name notation.
3. AppID
4. p12
a. A .p12 contains the certificate Apple needs in order to build and publish apps.
5. Organisation identifier
a. This will uniquely identifies the organisation from which it is developed.
6. Info.plist
a. Plist is short for PropertyList and it’s a file that automatically created for every
Xcode project. This file stores configuration information at the run time.
b. The information is stored in a format called key-value pair.
c. Similar to dictionary, the key is the property name and the value is property.
d. Example - Key = Status bar style and value =
String(UIStatusBarStyleLightContent)
39. Auto layout
Auto Layout constraints allows us to create views that dynamically adjust to different size
classes and positions. The constraints will make sure that your views will adjust to any size
changes without having to manually update frames or position.
1. Auto layout is a great way for making adjustments to a layout based on constraints.
But sometimes a layout requires more significant adjustments based on screen size,
device type and orientation.
39. Size Classes
You should focus instead on adjusting your layout to two types of widths(called
compact and regular) and two types of heights(called compact and regular).
1. You can use these size classes to define or adjust your layout.
2.
40. Access Controls
1. Open
2. Public
3. Internal
4. File private
5. private
41. Objective-C vs Swift
42. iOS 16 features
43. Cocoapods and CocoaTouch class
44. Thread Explosion
45. Deadlock
46. Final keyword
47. Notification Center
With Notification Center we can broadcast data from one part of your app to another
How it works
1. A listener that listens for notifications called observer
2. A sender that sends notifications when something happens.
3. The notification center itself will keep track of observers and notifications.
1. NotificationCenter.default.addObserver(_:selector:name:object)
a. The first parameter observer is unnamed, you provide it with a reference to
the object that is the observer for this notification.
b. Selector - is the function you want to call when the notification occurs, which
works like the target-action pattern
c. Name - name of the notification you want to listen for, which is of type
Notification.name
d. Object - optional object whose notifications you want to receive, so if you set
it, you will only receive notifications from that sender.
e. We need to remove observers either in viewWillDisAppear or deinit
2. NotificationCenter.default.post(name:object)
a. Name - name of the notification you want to post, it is of type
NotificationCenter.name
b. Object - the sender of the notification. It can be either nil or object.
3. One-to-many and Many-to-Many communication
4. When communication needs to happen repeatedly and consistently.
48. Button Hierarchy
UIButton -> UIControl -> UIView -> UIResponder -> NSObject
49. Silent notifications
50. URLSession parameters
51. How AES Encryption is done
52. What all reference types do we have in Swift
Class, function and closure
53. What all value types we have in Swift
Struct, Enum, Int, Double, String, Set, Array, Dictionary etc
54. Handshakes
55. Which method is called when notification is received to the App (when User uses
the App)
56. How to send images in Push Notifications
57. What are the advantages of using SwiftUI
58. View hierarchy
To debug the view we have Debug View Hierarchy tool in xcode
1. The Debug View Hierarchy in Xcode captures the snapshot of user interface and
allows to navigate and inspect view objects.
2. We can pause the app execution and introspect view hierarchy.
3. Responder Chain
a. The responder chain connects responder objects from a view to Application
delegate
b. UIView -> UIViewController -> UIWindow -> UIApplication ->
UIApplicationDelegate
4.
59. Image - Scale to Fill and Aspect Fit
60. Inout parameter
1. Function parameters are constants by default. If you try to change the value inside
the function, results in compile time error.
2. In-out parameter value can be changed inside function body and changes persist
after the function has ended
3. You can only pass variable as argument for an in-out parameter. You can’t pass a
constant or literal value as an argument.
4. In-out parameters can’t have default values.
5.
61. String Interpolation
It is a way of injecting custom data into strings at runtime. It replaces one or more parts of a
string with the data provided by us.
62. Solid principles
63. Apple design guidelines
64. QualityofService
65. Coredata vs SQLite
1. SQLite
a. Have data constraints feature
b. Operates on data, stored on disk
c. Can drop table and edit data with out loading them into memory
d. Slow compared to Core data
2. Coredata
a. Don’t have data constraints, if required need to implement by business logic
b. Operates on memory(data needs to be loaded from disk to memory)
c. Needs to load entire data if we need to drop a table or update data
d. Fast interms of record creation
e. For every entity we have attributes and relationships.
f. Attribute need to specified with data type.
g. Saving data
i. Refer to persistent container from appDelegate
ii. Create the context from persistent container
iii. Create an entity for the User
iv. Create new record with this User entity
v. Set values for the records for each key
h. Retrieve data
i. Refer to persistent container from AppDelegate
ii. Create a context from persistent container
iii. Prepare the request of type NSFetchRequest for the entity
iv. If required use predicate for filtering data
v. Fetch the result from context in the form of array of
[NSManagedObject]
vi. Iterate through an array to get value for the specific key
i. Update data
i. Refer to the persistent container from AppDelegate
ii. Create a new context from persistent container
iii. Prepare the request of type NSFetchRequest for the entity
iv. Use predicate for fetchRequest for fetching the record which was to be
updated
v. setNewValue with the key
vi. Lastly save context
j. Delete data
i. Refer to the persistent container from AppDelegate
ii. Create a new context from persistent container
iii. Prepare the fetch request of type NSFetchRequest for the entity
iv. Use NSPredicate for fetchRequest to fetch the record which was to
deleted
v. Use context.delete(object) for deleting the record
vi. Finally save the context using context.save()
66. Dependency Injection
67. Clang, Instruments and memory tuning, Shark
68. SpriteKit, PromiseKit
69. Jail break
70. Reverse engineering
71. Triggering time based notifications (example Alarm with app inactive)
72. Constantly fetching location(How it can be done?)
73. How to preview XIB without running the app
74. Variable catching
75. Async task execution hands-on
76. Storyboard adding different constraints (setting up UI in 3rd quadrent)
77. Camera functionality, File picker, image compression
78. Push notification badge count when app is not in use
79. How to store data in keychain in App
80. Tableview with custom cells
81. Keychain part how will you handle
82. Push notification images
83. Location permissions in
84. Any vs AnyObject
85. How to identify & fix memory leaks
86. Size class for iPhone & iPad
87. Content hugging priority
88. contentresistance
89. IBInspectable
90. IBDesignable
91. Storyboard localization
92. Generic protocol
93. Equatable, Hashable
94. Singleton disadvantages
95. Frame vs bound
Bounds refer to the views own coordinate system while frame refers to the views parent coordinate
system
1. View.bounds.origin.x, view.bounds.origin.y, view.bounds.size.width, view.bounds.sixe.height
2. View.bounds.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height
96. How to change app theme color and also it should affect all the views in the app

You might also like