50 Interview Questions
Every iOS Developer Should Know. (Part 2)

Gaurav Taywade
13 min readAug 1, 2017

--

Hope you guys like part 1 of this series. Let’s explore few more interview questions in part 2.

  1. How to animate view with constraint?
  • You need to call layoutIfNeeded within the animation block. Apple actually recommends you call it once before the animation block to ensure that all pending layout operations have been completed
  • You need to call it specifically on the parent view (e.g. self.view), not the child view that has the constraints attached to it. Doing so will update all constrained views, including animating other views that might be constrained to the view that you changed the constraint of (e.g. View B is attached to the bottom of View A and you just changed View A’s top offset and you want View B to animate with it)

2. Explain how you can add frameworks in Xcode project?

On the left column, select your project. There is an icon/button with your project’s name in the right pane. Click the UpDown icon and change from Project to Target. Then go to the General tab, scroll down to the Frameworks section and add/remove Frameworks.

3. Mention what is the use of PO command in Xcode?

The p command (a.k.a. expr — ) takes the arguments it is given, compiles them as though they were a source code expression written in the context of the current frame, executes the result — either by running an interpreter on the result of the compilation if that is possible, or by JITing the result of the compilation, inserting it into the target program, and running it there. Then it prints the result of the evaluation.

The po command (a.k.a. expr — O — ) does everything that p does, but instead of printing the result, if the result is a pointer to an ObjC object, it calls that object’s “description” method, and prints the string returned by that method(*). Similarly, if the result is a CF object, it will call CFShow and print the result of that. If both these attempts fail, it will go ahead and print the result as p would have.

4. Difference between bounds and frame?

The bounds of an UIView is the rectangle, expressed as a location (x,y) and size (width,height) relative to its own coordinate system (0,0). The frame of an UIView is the rectangle, expressed as a location (x,y) and size (width,height) relative to the superview it is contained within.

5. How we can do multithreading in iOS?

use GCD to achieve this, have a look on below

Step-1: Create the Queue using dispatch_queue_create

Step-2: Add the Block and call dispatch_async

6. How we can execute some code when app is in background?

Building on what rckoenes stated, applications are allowed to register background tasks to be completed after the user hits the home button. There is a time limit of 10 or 15 minutes for these tasks to complete. Again, you can register a task to complete immediately after the user hits home, this does NOT allow you to execute code say an hour after they exit the app.

7. How we can wait for some thread to finish before starting another?

The technique I’ve used before is to give the thread a selector to a method in the originating object (which is on the main thread). When the second thread is started, the main thread keeps executing, but puts up a busy indicator of some sort on the display. This allows user interaction to continue if required.

When the second thread ends, just before it shuts down, it calls the selector on the main thread. The method that the selector references then removes the busy indicator from the display and tells the main thread to update, picking up whatever data the second thread has generated.

Several technical ways to synchronize multi-threads, such as NSConditionLock(mutex-lock), NSCondition(semaphore)。But they are common programming knowledge for other languages(java…) besides objective-c.

8. How you will store user info (username, password or token) securely in iOS?

You should always use Keychain to store usernames and passwords, and since it’s stored securely and only accessible to your app, there is no need to delete it when app quits.

9. Why UIControl is provided if we can create custom UIView?

the UIControl class adds more support for interactivity. Most importantly, it adds the target/action pattern. Looking at the concrete subclasses, we can see buttons, date pickers, text fields, and more. When creating interactive controls, you often want to subclass a descendant of UIControl.

10. What are lifecycle events of UIViewController?

ViewDidLoad — Called when you create the class and load from xib. Great for initial setup and one-time-only work.

ViewWillAppear — Called right before your view appears, good for hiding/showing fields or any operations that you want to happen every time before the view is visible. Because you might be going back and forth between views, this will be called every time your view is about to appear on the screen.

ViewDidAppear — Called after the view appears — great place to start an animations or the loading of external data from an API.

ViewWillDisappear/DidDisappear — Same idea as ViewWillAppear/ViewDidAppear.

ViewDidUnload/ViewDidDispose — In Objective C, this is where you do your clean-up and release of stuff, but this is handled automatically so not much you really need to do here.

11. Difference between viewDidLoad and viewDidAppear?

viewDidLoad is called once when the controller is created and viewDidAppear is called each time the view, well, DID appear.

12. Is UIKit thread safe?

Drawing to a graphics context in UIKit is now thread-safe. Specifically:

The routines used to access and manipulate the graphics context can now correctly handle contexts residing on different threads. String and image drawing is now thread-safe. Using color and font objects in multiple threads is now safe to do.

13. Why do we override drawRect: method? How to explicitly call it?

You should never call drawRect yourself. Instead, you tell the system that drawing needs to be done by using the setNeedsDisplay method, which marks the view as dirty.

14. What are layers?

CALayers are simply classes representing a rectangle on the screen with visual content.

15. What are various singleton instances provided by frameworks? (UIApplication, NSFileManager, NSUserDefaults, etc.)

A singleton class returns the same instance no matter how many times an application requests it. Several Cocoa framework classes are singletons. They include NSFileManager, NSWorkspace, and, in UIKit, UIApplication and UIAccelerometer.

16. What is NSUserDefaults? What type of data can we store there?

NSUserDefaults is a class that allows simple storage of different data types. It is ideal for small bits of information you need to persist between app launches or device restarts. NSUserDefaults supports the following data types: NSString. NSNumber.

17. How do you check if your code has memory leaks?

The Leaks profiling template uses the Allocations and Leaks instruments to measure general memory usage in your app and check for leaks — memory that has been allocated to objects that are no longer referenced and reachable.

Read more here.

18. What does static analyser do?

Use the static analyzer to find bugs in your code before you even run your app. The static analyzer tries out thousands of possible code paths in a few seconds, reporting potential bugs that might have remained hidden or bugs that might be nearly impossible to replicate. This process also identifies areas in your code that don’t follow recommended API usage, such as Foundation, UIKit, and AppKit idioms.

19. What are different Instruments Xcode supports for app profiling?

CPU profiling, memory profiling and time profiling

20. Explain concept of notification center, local and remote notifications.

Notification Center is a feature in iOS[1] and macOS[2] that provides an overview of alerts from applications Local notifications and remote notifications are ways to inform users when new data becomes available for your app, even when your app is not running in the foreground.

With local notifications, your app configures the notification details locally and passes those details to the system, which then handles the delivery of the notification when your app is not in the foreground. Local notifications are supported on iOS, tvOS, and watchOS.

With remote notifications, you use one of your company’s servers to push data to user devices via the Apple Push Notification service. Remote notifications are supported on iOS, tvOS, watchOS, and macOS.

21. Have you uploaded app on Appstore? What is the process?

Answer for first question will be based on your experience.

Assemble App Store Information

Create a Bundle Identifier

Create a Certificate Signing Request

Create an App Store Production Certificate

Create a Production Provisioning Profile

Create an App Store Listing

Create a Release Build Fill in the Version Information

Submit Version for Review

Release

22. Difference between Developer and Enterprise Developer accounts?

Major difference between developer and enterprise developer account:

Developer account: Distribute your app via the App Store

Enterprise Account: Distribute proprietary apps directly to employees hosted by you and receive code level technical support

23. Common reasons for app rejection from Appstore review process?

  • Crashes and Bugs
  • Broken Links
  • Placeholder Content
  • Incomplete Information
  • Inaccurate Descriptions
  • Misleading Users
  • Substandard User Interface
  • Advertisements
  • Web clippings, content aggregators, or a collections of links
  • Repeated Submission of Similar Apps
  • Not enough lasting value

24. What do you mean by REST?

REST stands for Representational State Transfer. (It is sometimes spelled “ReST”.) It relies on a stateless, client-server, cacheable communications protocol — and in virtually all cases, the HTTP protocol is used

25. What is Wildcard App IDs?

A wildcard App ID contains an asterisk as the last part of its bundle ID search string. The asterisk replaces some or all of the bundle ID in the search string.

The asterisk is treated as a wildcard when matching the bundle ID search string with bundle IDs. For a wildcard App ID to match a set of apps, the bundle ID must exactly match all of the characters preceding the asterisk in the bundle ID search string. The asterisk matches all remaining characters in the bundle ID. The asterisk must match at least one character in the bundle ID.

26. Explain application sandboxing.

Sandboxing your app is a great way to protect systems and users by limiting the privileges of an app to its intended functionality, increasing the difficulty for malicious software to compromise your users’ systems.

App Sandbox is an access control technology provided in macOS, enforced at the kernel level. It is designed to contain damage to the system and the user’s data if an app becomes compromised. Apps distributed through the Mac App Store must adopt App Sandbox. Apps signed and distributed outside of the Mac App Store with Developer ID can (and in most cases should) use App Sandbox as well.

27. Explain ~/Documents, ~/Library, ~/tmp. What directory is ~ on iOS?

tmp/ Use this directory to write temporary files that do not need to persist between launches of your app. Your app should remove files from this directory when they are no longer needed; however, the system may purge this directory when your app is not running. The contents of this directory are not backed up by iTunes or iCloud.

Library/ This is the top-level directory for any files that are not user data files. You typically put files in one of several standard subdirectories. iOS apps commonly use the Application Support and Caches subdirectories; however, you can create custom subdirectories. Use the Library subdirectories for any files you don’t want exposed to the user. Your app should not use these directories for user data files. The contents of the Library directory (with the exception of the Caches subdirectory) are backed up by iTunes and iCloud. For additional information about the Library directory and its commonly used subdirectories, see The Library Directory Stores App-Specific Files.

Documents/ Use this directory to store user-generated content. The contents of this directory can be made available to the user through file sharing; therefore, his directory should only contain files that you may wish to expose to the user. The contents of this directory are backed up by iTunes and iCloud.

28.How to de-symbolicate crash log?

  • Take any .xcarchive file. If you have one from before you can use that. If you don’t have one, create one by running the Product > Archive from Xcode.
  • Right click on the .xcarchive file and select ‘Show Package Contents’
  • Copy the dsym file (of the version of app that crashed) to the dSYMs folder
  • Copy the .app file (of the version of app that crashed) to the Products > Applications folder.
  • Edit the Info.plist and edit the CFBundleShortVersionString and CFBundleVersion under the ApplicationProperties dictionary. This will help you identify the archive later
  • Double click the .xcarchive to import it to Xcode. It should open Organizer.
  • Go back to the crash log (in Devices window in Xcode)
  • Drag your .crash file there (if not already present)
  • The entire crash log should now be symbolicated. If not, then right click and select ‘Re-symbolicate crash log’

29. How many types of background modes supported in iOS?

  • Audio and AirPlay
  • Location updates
  • Voice over IP
  • Newsstand downloads
  • External accessory communication
  • Uses Bluetooth LE accessories
  • Acts as a Bluetooth LE accessory
  • Background fetch
  • Remote notifications

30.What is NSPersistentStoreCoordinator ? What duties does it perform?

A coordinator that associates persistent stores with a model (or a configuration of a model) and that mediates between the persistent stores and the managed object contexts.

31. What is NSPersistentStore ? Is it thread safe?

The abstract base class for all Core Data persistent stores. Yes its thread safe.

32. What is NSManagedObjectContext ? What are the different concurrency types? Explain each type.

An object representing a single object space or scratch pad that you use to fetch, create, and save managed objects.

Private queue (privateQueueConcurrencyType): The context creates and manages a private queue.

Main queue (mainQueueConcurrencyType): The context is associated with the main queue, and as such is tied into the application’s event loop, but it is otherwise similar to a private queue-based context. You use this queue type for contexts linked to controllers and UI objects that are required to be used only on the main thread.

33. Different types of persistent stores? Which all types can we have on iOS?

XML Automatic, Binary Automatic, SQLite, In-Memory

34. Can my application have multiple models?

Yes

35. In a single model, can I have few entities in one sqlite db file and remaining in another sqlite db file? (Yes, Hint: configurations)

Yes, you can do this using ATTACH

36. What is difference between performBlock: and performBlockAndWait: ?

performBlock is asynchronous, in that it returns immediately, and the block is executed at some time in the future, on some undisclosed thread. All blocks given to the MOC via performBlock will execute in the order they were added.

performBlockAndWait is synchronous, in that the calling thread will wait until the block has executed before returning. Whether the block runs in some other thread, or runs in the calling thread is not all that important, and is an implementation detail that can’t be trusted.

37. From which iOS version, ARC is supported?

ARC is supported on iOS 4.3 and above.

38. Why do you generally create a weak reference when using self in a block?

You don’t have to always use a weak reference. If your block is not retained, but executed and then discarded, you can capture self strongly, as it will not create a retain cycle. In some cases, you even want the block to hold the self until the completion of the block so it does not deallocate prematurely. If, however, you capture the block strongly, and inside capture self, it will create a retain cycle.

39. What is memory management handled on iOS?

Memory management is the programming discipline of managing the life cycles of objects and freeing them when they are no longer needed. Managing object memory is a matter of performance; if an application doesn’t free unneeded objects, its memory footprint grows and performance suffers.

40. What is the difference between weak and strong?

Strong: A strong reference is a reference to an object that stops it from being deallocated. In other words it creates a owner relationship.

Weak: A weak reference is a reference to an object that does not stop it from being deallocated. In other words, it does not create an owner relationship

41. What is a memory leak?

Memory leaks are blocks of allocated memory that the program no longer references. Leaks waste space by filling up pages of memory with inaccessible data and waste time due to extra paging activity.

42. What is a retain cycle?

Retain Cycle is the condition When 2 objects keep a reference to each other and are retained, it creates a retain cycle since both objects try to retain each other, making it impossible to release.

43. What is the difference between copy and retain?

Retain increases the retain count of an object by 1 and takes ownership of an object. Whereas copy will copy the data present in the memory location and will assign it to the variable so in the case of copy you are first copying the data from a location assign it to the variable which increases the retain count.

44. Explain difference between MRC and ARC. or What are advantages of ARC over MRC?

In ARC the OS looks after the memory management, so you don’t have to worry about releasing the objects. It’s pretty neat for beginners. Whereas in Manual counting you will have to keep track of releasing the memory and if you don’t do it right you will end up crashing your app

45. ARC is compile time or Run time feature?

Its compile time feature

46. What is a difference between stack/heap memory?

Stack is used for static memory allocation and Heap for dynamic memory allocation

47. Difference between strong and retain.

The differences between strong and retain:

In iOS4, strong is equal to retain It means that you own the object and keep it in the heap until don’t point to it anymore If you write retain it will automatically work just like strong

48.Whats threadsafe?

A code is thread safe if it behaves correctly when accessed from multiple threads, regardless of the scheduling or interleaving of the execution of those threads by the runtime environment,and with no additional synchronization or other coordination on the part of the calling code.

49. What is difference between Unit tests and UI Test in Xcode?

UI testing gives you the ability to find and interact with the UI of your app in order to validate the properties and state of the UI elements.

Unit Testing is a tool, just like any other tool. Its purpose is to make us better at our jobs, which is to produce robust, maintainable software. It’s a simple enough premise: write code to construct environments that exercise the particular behavior of a given method, function, class, or feature. Variables are isolated in a scientific manner, so as to test assumptions with logical atomicity.

50.Explain XCtest test case code.

  • Test Targets, Test Bundles, and the Test Navigator
  • Creating a Test Class
  • Test Class Structure
  • Flow of Test Execution
  • Writing Test Methods
  • Writing Tests of Asynchronous Operations
  • Writing Performance Tests
  • Writing UI Tests
  • XCTest Assertions

Thank you for reading this post, your suggestions are always welcome.

As always, credit for this goes to all blogs, tutorial and Documents available over internet.

Best luck for your interview.

--

--