Top IOS Interview Questions and Answers (Sept 2018) Part 2

iOS latest interview questions

Top IOS Interview Questions and Answers (Sept 2018) Part 2

iOS latest interview questions

In this article, i am adding new question asked recently to iOS developers, lets start..

Q1. What is NSZombie?

When your iPhone app crashes with ‘BAD ACCESS’ you’re in trouble — a memory bug where you tried to call a method on a object that was already deleted. Instruments has support for NSZombie — a feature that makes it easy to find the source of the bug by showing you a full history of every alloc, retain, release, and autorelease of the object that caused the crash! Wow.

It’s a memory debugging aid. Specifically, when you set NSZombieEnabled then whenever an object reaches retain count 0, rather than being deallocated it morphs itself into an NSZombieinstance. Whenever such a zombie receives a message, it logs a warning rather than crashing or behaving in an unpredictable way. As such, you can debug subtle over-release/autorelease problems without advanced tools or painstaking needle in haystack searches.

The name is a fairly obvious play on the fact that objects are normally considered “dead” when they reach retain count 0. With this setting, they continue to exist in a strange half-life — neither living, nor quite dead. Much like real zombies, except they eat rather fewer brains.

Q2. What is Thread Sanitizer and Static Analysis?

The Thread Sanitizer will help you find data races and other concurrency bugs.

The static analyzer has been extended to search for localizability issues, check nullability, and find memory leaks in MRR code.

Q3. What is Deferred invocations? Write sample code?

Using libdispatch, the simplest form of timer is DispatchQueue.asyncAfter. This is a form of “deferred invocation” that simply delays a function but returns no reference and therefore offers no possibility for cancellation.

A basic after invocation might look something like this:

DispatchQueue.global().asyncAfter(deadline: DispatchTime.now() + .seconds(10)) {
// Some deferred code
}

Q4. What is dispatch source?

A dispatch source is a fundamental data type that coordinates the processing of specific low-level system events. Grand Central Dispatch supports the following types of dispatch sources:

  • Timer dispatch sources generate periodic notifications.
  • Signal dispatch sources notify you when a UNIX signal arrives.
  • Descriptor sources notify you of various file- and socket-based operations, such as:
  1. When data is available for reading
  2. When it is possible to write data
  3. When files are deleted, moved, or renamed in the file system
  4. When file meta information changes
  • Process dispatch sources notify you of process-related events, such as:
  1. When a process exits
  2. When a process issues a fork or exec type of call
  3. When a signal is delivered to the process
  • Mach port dispatch sources notify you of Mach-related events.
  • Custom dispatch sources are ones you define and trigger yourself.

Q5. What is app thinning?

The App Store and operating system optimize the installation of iOS, tvOS, and watchOS apps by tailoring app delivery to the capabilities of the user’s particular device, with minimal footprint. This optimization, called app thinning, lets you create apps that use the most device features, occupy minimum disk space, and accommodate future updates that can be applied by Apple. Faster downloads and more space for other apps and content provides a better user experience.

Slicing

Slicing is the process of creating and delivering variants of the app bundle for different target devices. A variant contains only the executable architecture and resources that are needed for the target device. You continue to develop and upload full versions of your app to App Store Connect. The App Store will create and deliver different variants based on the devices your app supports. Use asset catalogs so that the App Store can select images, GPU resources, and other data appropriate for each device variant. When the user installs an app, a variant for the user’s device is downloaded and installed.

Reference: Apple

Bitcode

Bitcode is an intermediate representation of a compiled program. Apps you upload to App Store Connect that contain bitcode will be compiled and linked on the App Store. Including bitcode will allow Apple to re-optimize your app binary in the future without the need to submit a new version of your app to the App Store.

Q6. Tell me about dsym, how it work and what it is?

  1. As the compiler translates your source code into machine code, it also generates debug symbols which map each machine instruction in the compiled binary back to the line of source code from which it originated. Depending on the Debug Information Format(DEBUG_INFORMATION_FORMAT) build setting, these debug symbols are stored inside the binary or in a companion Debug Symbol (dSYM) file. By default, debug builds of an application store the debug symbols inside the compiled binary while release builds of an application store the debug symbols in a companion dSYM file to reduce the binary size.
    The Debug Symbol file and application binary are tied together on a per-build-basis by the build UUID. A new UUID is generated for each build of your application and uniquely identifies that build. Even if a functionally-identical executable is rebuilt from the same source code, with the same compiler settings, it will have a different build UUID. Debug Symbol files from subsequent builds, even from the same source files, will not interoperate with binaries from other builds.
  2. When you archive the application for distribution, Xcode will gather the application binary along with the .dSYM file and store them at a location inside your home folder. You can find all of your archived applications in the Xcode Organizer under the "Archived" section. For more information about creating an archive, refer to the App Distribution Guide.

References:

  1. https://stackoverflow.com/questions/4168327/what-is-nszombie
  2. https://developer.apple.com/videos/play/wwdc2016/412/
  3. https://www.cocoawithlove.com/blog/2016/07/30/timer-problems.html
  4. https://developer.apple.com/library/archive/documentation/General/Conceptual/ConcurrencyProgrammingGuide/GCDWorkQueues/GCDWorkQueues.html
  5. https://help.apple.com/xcode/mac/current/#/devbbdc5ce4f
  6. https://developer.apple.com/library/archive/technotes/tn2151/_index.html