IOS Interview Questions Answers

  • What is an iOS application?

    An iOS application, or app, is a software program designed to run on Apple's iOS operating system, which is used on devices such as the iPhone, iPad, and iPod Touch. When creating an iOS app, your code is typically written in a programming language like Swift or Objective-C, and is responsible for implementing the app's desired functionality and behavior. This code is integrated into the overall structure of the app, which includes a user interface (UI) and other resources like image and sound files. The app is then compiled and packaged into a binary file that can be installed and run on an iOS device.

  • What is fast enumeration and struct?

    Fast enumeration is a language feature that allows you to enumerate over the contents of a collection.

    A struct is a special C data type that encapsulates other pieces of data into a single cohesive unit. Like an object, but built into C.

  • Explain View Controller Lifecycle events order ?

    There are a few different lifecycle event

    1. LoadView-Creates the view that the controller manages.

    2. ViewDidLoad-Called after the controller’s view is loaded into memory.

    3. ViewWillAppear-It’s called whenever the view is presented on the screen.Here orientation is not applied

    4. ViewWillLayoutSubviews-Called to notify the view controller that its view is about to layout its subviews. This method is called every time the frame changes.

    5. ViewDidLayoutSubviews- Called every time the view is updated.

    6. ViewDidAppear-Notifies the view controller that its view was added to a view hierarchy.

    7. ViewWillDisappear-Called to remove origin view controller from screen before the transition to the next view controller happens

    8. ViewDidDisappear-Called after a view controller gets removed from the screen.

  • What are mutable and immutable types in Objective C?

    Mutable means once they are initialised, their values cannot be changed. On the otherhand immutable means it can be changed or updated.

  • Explain Dispatch Barriers and Dispatch group in Swift 3?

    Dispatch barriers are used in concurrent programming to provide mutual exclusion for certain operations, ensuring that only one operation can access a shared resource at a time. This is useful for preventing data races and other synchronization issues when multiple threads or processes are accessing the same data.

    Dispatch groups are used to manage a group of operations and track their completion status. They allow you to submit multiple operations to a dispatch queue, and then wait for all of the operations to complete or be cancelled before continuing with other tasks. Dispatch groups can be used to implement synchronization between operations, or to perform actions after all operations in the group have finished.

  • What is FRP (Functional Reactive Programming)?

    Functional Reactive Programming (FRP) is a programming paradigm that combines functional programming and reactive programming. In FRP, data flows are modeled as streams of values over time, and operations on these streams are expressed as pure functions. This allows developers to write programs in a declarative and reactive style, where the focus is on specifying the relationships between data flows, rather than the control flow of the program.

  • Is a delegate retained?

    No, the delegate is never retained.

    If I call performSelector:withObject:afterDelay: retained? Yes, the object is retained. It creates a timer that calls a selector on the current threads run loop. It may not be 100% precise time-wise as it attempts to dequeue the message from the run loop and perform the selector.

    Is the delegate for a CAAnimation retained:Yes This is one of the rare exceptions to memory management rules.

  • What is dynamic keyword in iOS?

    You use the @dynamic keyword to tell the compiler that you will fulfil the API contract implied by a property either by providing method implementations directly or at runtime using other mechanisms such as dynamic loading of code or dynamic method resolution. It suppresses the warnings that the compiler would otherwise generate if it can’t find suitable implementations. You should use it only if you know that the methods will be available at runtime.

  • Outline the class hierarchy for a UIButton until NSObject?

    UIButton inherits from UIControl, UIControl inherits from UIView, UIView inherits from UIResponder, UIResponder inherits from the root class NSObject.

  • What is pair programming?

    Pair programming is a software development methodology in which two programmers work together at one computer, with one person writing the code and the other reviewing it. This allows the programmers to share their knowledge and skills, and to collaborate on solving problems and developing solutions. Pair programming can improve the quality and efficiency of the code, as well as enhance the learning and professional development of the programmers.

    In pair programming, the two programmers typically switch roles frequently, with one person acting as the "driver" who writes the code, and the other person acting as the "observer" or "navigator" who reviews the code and provides feedback and suggestions. This allows both programmers to stay engaged and focused, and to share the workload and responsibilities of the programming task. Pair programming can be done in person or remotely, using tools such as video conferencing and screen sharing software

  • What is code review?

    Code review is the practice of reviewing and analyzing source code in order to find defects, improve its quality, and enhance its maintainability. Code review is typically done by other members of the development team or by peers, who use a variety of techniques and tools to analyze the code and identify potential issues or improvements.

    Code review is the practice of reviewing and analyzing source code in order to find defects, improve its quality, and enhance its maintainability. Code review is typically done by other members of the development team or by peers, who use a variety of techniques and tools to analyze the code and identify potential issues or improvements.

  • How to change the Application Name?

    To change the application name in Xcode 13, follow these steps:

    1. Open your project in Xcode 13.

    2. In the Project navigator, click on the top-level project node to open the project editor.

    3. In the General tab, scroll down to the Identity section.

    4. In the Identity section, find the Bundle Name field and enter the new application name.

    5. In the same section, find the Bundle Identifier field and update the name of the bundle identifier to match the new application name.

    6. Save your changes by clicking on the Save button in the top-right corner of the Xcode window.

    7. In the Product menu, select Clean Build Folder to clean the build artifacts and rebuild your project with the new application name.

  • What is the use of NSCoder class ?

    The NSCoder class is a general-purpose abstract class in the Foundation framework, used for encoding and decoding objects and values into a compact binary format. NSCoder is commonly used in iOS and macOS development for storing and retrieving data in persistent storage, such as files and databases.

  • What is SpriteKit and what is SceneKit?

    SpriteKit is a framework for easy development of animated 2D objects. SceneKit is a framework inherited from OS X that assists with 3D graphics rendering.

  • What is git stash?

    Git stash is a command in the Git version control system that allows you to save changes in your working directory, without committing them to the local repository. This is useful when you need to switch to a different branch or work on another task, but you don't want to lose the changes you've made in your current branch.

  • What is the function of ‘git stash apply’?

    The git stash apply command is used in the Git version control system to apply the changes from a stash onto the current working directory and branch. This restores the state of the working directory to the state it was in when the changes were stashed, but does not remove the stash from the repository.

    When you use the git stash apply command, the changes from the stash are applied to the working directory and the local repository, but they are not committed. This allows you to review the changes and make any necessary modifications before committing them to the repository. If you want to remove the stash from the repository after applying it, you can use the git stash drop command.

    The git stash apply command is typically used after the git stash command, which saves the changes in the working directory to a stash. It can also be used with the git stash list command, to apply a specific stash from the stash list by specifying its stash index or stash name.

  • What is git reflog?

    The ‘reflog’ command keeps a track of every single change made in the references (branches or tags) off a repository and keeps a log history of the branches and tags that were either created locally or checked out.

  • What is WebHooks?

    Web hooks allow external services to be notified when certain events happen within your repository.

  • What are the App states. Explain them?

    • Not running State: The app has not been launched or was running but was terminated by the system.

    Inactive state: The app is running in the foreground but is currently not receiving events. (It may be executing other code though.) An app usually stays in this state only briefly as it transitions to a different state. The only time it stays inactive for any period of time is when the user locks the screen or the system prompts the user to respond to some event, such as an incoming phone call or SMS message.

    Active state: The app is running in the foreground and is receiving events. This is the normal mode for foreground apps.

    Background state: The app is in the background and executing code. Most apps enter this state briefly on their way to being suspended. However, an app that requests extra execution time may remain in this state for a period of time. In addition, an app being launched directly into the background enters this state instead of the inactive state. For information about how to execute code while in the background, see “Background Execution and Multitasking.”

    Suspended state: The app is in the background but is not executing code. The system moves apps to this state automatically and does not notify them before doing so. While suspended, an app remains in memory but does not execute any code. When a low-memory condition occurs, the system may purge suspended apps without notice to make more space for the foreground app.

  • What is Automatic Reference Counting (ARC) and How is memory management handled in iOS?

    Automatic Reference Counting (ARC) is a memory management feature in the Objective-C and Swift programming languages. It automatically keeps track of how many references, or "pointers," point to a given object in memory, and frees up the memory for that object when it is no longer needed. This is a form of garbage collection, which helps to prevent memory leaks and reduce the amount of memory used by an app.

    In iOS, memory management is handled by the operating system and the ARC system. When an app is no longer in use, the operating system will automatically release the memory used by that app, making it available for other apps or processes. This helps to ensure that the system as a whole remains stable and responsive. In general, iOS developers do not need to worry about explicitly managing memory, as this is handled automatically by ARC and the operating system. However, they may need to be aware of how their app is using memory, and take steps to optimize its memory usage if necessary. For example, they may need to be careful about creating and destroying objects in a way that minimizes the number of objects in memory at any given time.

  • What is the Responder Chain?

    The responder chain is a hierarchical chain of objects that are responsible for handling events in iOS. Each object in the chain has the opportunity to handle an event, and if it is unable to do so, it passes the event up the chain to the next object. This allows for a flexible and modular way of handling events in iOS apps.

    The responder chain begins with the first responder, which is typically the object that is currently receiving input from the user. For example, if the user is interacting with a text field, the text field would be the first responder. If the text field is unable to handle a particular event, it would pass the event up the chain to the next responder, which could be its parent view, or a view controller that manages the view. The event would continue to be passed up the chain until it is handled, or until it reaches the end of the chain.

    The responder chain is an important concept in iOS development, as it allows for a flexible and modular approach to handling events. It also allows for a clear separation of responsibilities between different objects in the app, which can help to make the code easier to maintain and understand.

  • What is the difference between delegates, notifications, KVC, KVO and Notification Center?

    Delegates are used for one-to-one communication between objects.

    Notifications are used for broadcasting messages to multiple objects.

    KVC and KVO are used for accessing and observing the values of object properties.

    Notification Center is the service that manages notifications and delivers them to registered objects.

  • What is posing in iOS?

    In iOS, posing refers to a technique for replacing the implementation of a class with a new implementation. This allows for a subclass to effectively "pose" as another class, providing its own custom implementation for the methods and properties of the original class.

    Posing is often used in testing or debugging, as a way to inject test or mock implementations of classes into an app without modifying the original source code. This can help to ensure that the app is tested thoroughly, without relying on external dependencies such as network services or databases.

  • How do you manage dependencies?

    There are several ways to manage dependencies in iOS development. Some common techniques include:

    Using a dependency manager, such as CocoaPods or Carthage, which allows for easy installation and management of third-party libraries and frameworks.

    Using a package manager, such as Swift Package Manager, which allows for easy installation and management of packages containing reusable code.

    Using Git sub modules, which allow for dependencies to be included as part of a Git repository, so that they can be easily tracked and managed along with the rest of the code.

    Manually adding dependencies to an Xcode project, by including the source code or binary files for the dependency directly in the project.

  • Explain codable Protocol ?

    The Codable protocol is a built-in Swift protocol that provides a standardized way of encoding and decoding data. It combines the functionality of the Encodable and Decodable protocols, and allows for easy conversion between types such as classes, structures, and enums, and their corresponding data representations, such as JSON or Property List.

  • What is the use of SwiftLint in iOS?

    SwiftLint is an open-source tool to enforce Swift style and convention.It allows us to enforce code style rules and stick to it during the development of iOS apps.You can integrate SwiftLint into the development process and show you how to set up in your local machine and Jenkins server to run the SwiftLint automatically.

  • Who calls the main function of your app during the app launch cycle?

    When an app is launched, the system creates a main thread for the app and calls the app's main function on that thread. The main function is the entry point for the app, and is where the app sets up any initial state and begins executing the app's code. In most cases, the system will call the main function automatically, without any intervention from the app developer.

  • Explain static and dynamic library/framework in iOS?

    Static library - a unit of code linked at compile time, which does not change. However, iOS static libraries are not allowed to contain images/assets (only code).You can get around this challenge by using a media bundle though.

    Dynamic library - a unit of code and/or assets linked at runtime that may change. However, only Apple is allowed to create dynamic libraries for iOS.You're not allowed to create these, as this will get your app rejected.

  • What are the common reasons for app rejection from App store review process?

    Broken Links

    Bugs throughout the review method

    Crashes throughout the review method

    Long loading times

    Poor interface

    Apps that square measure demos or in beta

    Mistreated non-public API

    Inappropriate ad identifiers

    Inappropriate content

    Combination content

    Unrelated keywords

    Offensive language

    No privacy policy

    Sharing personal user knowledge

    Missing information

  • Explain the difference between Unlocking and jail breaking in iPhone ?

    Unlocking an iPhone refers to the process of removing the carrier restrictions on the device, allowing it to be used with any carrier. This is typically done by entering a special code into the phone, which is provided by the carrier or a third-party service.

    By contrast, jail breaking an iPhone refers to the process of removing the limitations imposed by Apple on the device's operating system, allowing users to install unauthorized software and make other modifications to the system. This is often done to allow the iPhone to run software or make changes that are not otherwise possible with the stock operating system

  • Define property, synthesised and instance variable?

    A property is a value associated with an object or class. It is a named piece of data that can be accessed and potentially modified by the object or class, as well as by other code.

    A synthesized property is a property that is automatically generated by the compiler based on the information provided in the code.

    Instance variable is a variable that is associated with a specific instance of an object or class.

  • What are the protocols used in table view?

    In the context of a table view, the protocols that are typically used are the UITableViewDelegate and UITableViewDataSource protocols. These protocols define the methods that are used to manage the data and the appearance of the table view, such as configuring cells, handling user interactions, and managing the data source. Implementing these protocols allows the table view to display data and respond to user input in a consistent and predictable way.

  • What are the uses of reuse Identifier?

    In iOS development, the reuse identifier is a string that is associated with a reusable table view cell or collection view cell. It is used to identify cells that can be reused, allowing the table view or collection view to recycle cells and improve performance. When a cell is no longer needed on the screen, it is placed in a reuse queue, where it can be dequeued and used again later when a new cell is needed. By using the same reuse identifier for cells that can be recycled, the table view or collection view can easily identify cells that can be reused, improving performance and minimizing memory usage.

  • What options do you have for implementing storage, database and persistence on iOS?

    There are several options for implementing storage, database, and persistence on iOS. Some common options include:

    Using property lists, which allow you to store simple data in a structured format. Property lists are easy to use and can be accessed quickly, but they have limited capabilities and are not suitable for complex data structures.

    Using the user defaults system, which allows you to store small amounts of data in a dictionary-like structure. The user defaults system is simple to use and can be accessed quickly, but it is not suitable for large amounts of data or complex data structures.

    Using Core Data, which is a powerful framework for managing and persisting data. Core Data provides an object-oriented interface for working with data, and it can handle large amounts of data and complex data structures. However, it can be more difficult to learn and use than some other options.

    Using SQLite, which is a lightweight, embedded database system. SQLite is widely used, and it provides a flexible and powerful way to manage and query data. However, it requires more knowledge and expertise to use than some other options.

    Using cloud services, such as iCloud or Firebase, which allow you to store data in the cloud and access it from multiple devices. Cloud services are convenient and scalable, but they require an internet connection and may not be suitable for all types of data.

  • What is the major purposes of Frameworks?

    Frameworks have three major purposes:

    Code encapsulation

    Code modularity

    Code reuse

  • What are the five frameworks used in iPhone?

    • UI kit framework

    Map kit framework

    ADI kit framework

    Core data framework

    Core foundation framework

  • What is the instance method, class method and accessor methods?

    Instance methods are essentially code routines that perform tasks so instances of classes. we create object to access, methods to get and set the instance variables and to display the current values of these variables.

    Class methods work at the class level and are common to all instance of a class these methods are specific to the class overall as opposed to working on different instance data encapsulated in each class instance.

    Accessor methods are methods belonging to a class that allow to get and set the values of instance valuables contained within the class.

  • Difference between shallow copy and deep copy?

    Shallow copy is also known as address copy where it copy address not actual data while in deep copy you copy data.

  • What is the navigation controller and split view controller?

    The navigation controller and split view controller are two classes that are part of the UI Kit framework, which is used to develop user interfaces for iOS apps.

    A navigation controller is a type of view controller that manages the display of hierarchical content. It is commonly used in apps that have a hierarchical data structure, such as a navigation app or a file manager app. The navigation controller manages a stack of view controllers, which are the individual screens that make up the app. It allows the user to navigate through the app by pushing new view controllers onto the stack, or popping view controllers off the stack to go back to a previous screen.

    A split view controller, on the other hand, is a container view controller that manages the display of two view controllers side by side. It is commonly used in apps that display a master list on one side of the screen, and the details for the selected item on the other side. For example, the Mail app on iOS uses a split view controller to display a list of email folders on the left side of the screen, and the messages in the selected folder on the right side.

    Overall, both the navigation controller and split view controller are useful tools for managing the flow of an iOS app, and they are commonly used together in apps that have a hierarchical data structure.

  • What is meant by App Thinning?

    App thinning is the process of creating and delivering optimized versions of an app binary that are tailored to a specific target device, so that only the code and resources that are needed for that device are included in the app package. This can result in smaller app sizes, which can reduce the amount of storage space required on the user's device, and can also improve the performance of the app by only loading the code and resources that are actually needed.

    There are several types of app thinning that can be used, including slicing, bitcode, and on-demand resources.

    Slicing involves creating multiple versions of the app binary, each of which is optimized for a specific target device and architecture.

    Bitcode is a feature that allows the App Store to optimize the app binary further when it is downloaded, by re-compiling it for the specific device and architecture that it is being installed on.

    On-demand resources allow the app to download additional resources only when they are needed, rather than including them in the initial app binary.

  • Why category is better than inheritance?

    One of the main advantages of categories is that they allow you to add new methods to an existing class, without having to create a subclass. This means that you can extend the functionality of a class without changing the original code, which can be useful if you don't have access to the source code for the class, or if you don't want to modify the class in order to avoid breaking existing code that depends on the original implementation

    Another advantage of categories is that they allow you to organize your code into logical units that are related to specific areas of functionality, rather than creating a large hierarchy of subclasses. This can make your code easier to understand and maintain, because the categories are self-contained and focused on specific tasks, rather than being organized around a hierarchy of classes.

  • Difference between Formal and informal protocol?

    Formal protocols are defined using the @protocol keyword, and they specify the name of the protocol and a list of the methods that a class must implement in order to conform to the protocol. Formal protocols are useful for defining the interface of a class, and for ensuring that a class implements a specific set of methods

    Informal protocols are defined using the @interface keyword, and they specify a list of optional methods that a class can implement. Unlike formal protocols, informal protocols do not require a class to implement any of the methods in the protocol, and they do not define a specific interface for a class. Informal protocols are useful for defining optional behavior that a class may choose to implement, but they do not provide the same level of type safety and compile-time checking as formal protocols.

    Overall, the main difference between formal and informal protocols in Objective-C is that formal protocols define a specific interface that a class must implement, while informal protocols define optional behavior that a class may choose to implement. Formal protocols provide more type safety and compile-time checking, while informal protocols provide more flexibility and allow a class to implement only the methods that are relevant to its specific behavior.

  • Difference between Optional and required?

    Protocol methods can be marked as optional using the @optional keyword. Corresponding to the @optional modal keyword, there is a @required keyword to formally denote the semantics of the default behaviour. You can use @optional and @required to partition your protocol into sections as you see fit. If you do not specify any keyword, the default is @required.

  • What is the difference between Stack and Heap ?

    Stack

    The stack is used for storing local variables and function parameters.

    The memory is automatically allocated and deallocated in the stack.The stack is generally faster and more efficient than the heap, but it is also more limited in the amount of memory it can allocate.

    The stack has a fixed size This means that the stack is better suited for storing small amounts of data that are used frequently.

    The stack is used for short-term storage in iOS.

    The stack is faster but more limited.

    Heap

    The heap is used for dynamically allocating memory during program execution

    The memory allocation must be done manually in the heap. The heap is less efficient but can allocate more memory.

    The heap can grow and shrink as needed in size. The heap is better for storing large amounts of data that are not used as frequently.

    The heap is used for long-term storage

    The heap is slower but more flexible.

  • How should one handle errors in Swift?

    In Swift, errors are thrown and handled inside of do-catch blocks. The method for handling errors in Swift differ a bit from Objective-C. In Swift, it's possible to declare that a function throws an error. It is, therefore, the caller's responsibility to handle the error or propagate it. This is similar to how Java handles the situation. You simply declare that a function can throw an error by appending the throws keyword to the function name. Any function that calls such a method must call it from a try block .func can Throw Errors() throws -> String