iOS Interview Questions — Part 2

Rathish Kannan
6 min readFeb 13, 2019

--

Some of the areas to refresh before an iOS Technical Interview.

Questions:

  • What’s Lazy var in Swift ?
  • TDD ? — Explain the process of development with TDD (refactor / green & red)
  • What’s PMD — Mention some swift static code analysis tool ?
  • ARC Swift
  • Difference between Static & Dynamic Libs ?
  • Advantages using Carthage/ Swift Package Manager over Pods ?
  • How to create readonly external, readwrite internal property in Swift ?
  • What is git fork ?
  • Difference — git merge and rebase ?

Answers:

  1. Lazy var
  • A lazy stored property is a property whose initial value is not calculated until the first time it is used. You indicate a lazy stored property by writing the lazy modifier before its declaration.
  • The lazy property is marked as lazy var. You can't make it lazy let because lazy properties must always be variables.
  • Because the actual value is created by evaluation, you need to declare its data type up front.

Ref: https://www.hackingwithswift.com/example-code/language/what-are-lazy-variables

2 . TDD — Test Driven Development

The methodology dictates that you write tests before writing supporting code

The Red-Green-Refactor TDD Cycle

In essence, TDD is performed with the Red-Green-Refactor cycle. The three steps are:

  1. RED — Write a failing test
  2. GREEN — Write the minimum amount of code to make the test pass
  3. REFACTOR — Refactor both the app code and test code

You write a failing test to go into the RED state. Next, you write just enough code to transition to the GREEN state. Finally, you REFACTOR both your app code and test code while staying in GREEN. You then move on to the next test.

How to create app with TDD ?

Ref : https://medium.com/swift-india/test-driven-development-in-ios-swift-4x-6b8fa57a0b38

Thanks to G. Abhisek

3 . What’s PMD — Mention some swift static code analysis tool ?

Static Code Analysis

  • Static code analysis is a method of analyzing and evaluating code without executing a program

Ref : some of the most used tools codebeat, SwiftLint & Tailor

PMD

  • A cross-language static code analyzer. (Supports Swift)

Ref : PMD

4 . ARC Swift

  • Automatic Reference Counting (ARC)
  • Retain Cycles — When two class instance holds a strong Reference to each other and there is no way for the system to deallocate them
  • Ref : https://medium.com/swift-india/swift-4-0-automatic-reference-counting-arc-part-1-d21d3ccf12b5
  • Note : Reference Counting applies only to the instances of the Class because it is Reference Type. This means that multiple objects can refer to the same object. Where as Structures and Enumerations are Value Types

Ref: https://docs.swift.org/swift-book/LanguageGuide/AutomaticReferenceCounting.html

5 . Difference between Static & Dynamic Libs ?

  • Library Libraries are files that define pieces of code and data that are not a part of your Xcode target..
  • Framework — Framework is a package that can contain resources such as dynamic libraries, strings, headers, images, storyboards etc.
  1. Static Library
  • Static libraries are collections of object files. In its turn, object file is just a name for a file that comes out of a compiler and contains machine code
  • Static libraries are built for particular(defined) architecture, however this can be extended using the Lipo tool
  • Are loaded into memory even when complied (takes longer time to compile)

2. Dynamic Library

  • Dynamic libraries, as opposed to the static ones, rather than being copied into single monolithic executable, are loaded into memory when they are actually needed. This could happen either at load time or at runtime
  • All iOS and macOS system libraries are dynamic.

Ref: http://www.vadimbulavin.com/static-dynamic-frameworks-and-libraries/

6 . Advantages using Carthage/ Swift Package Manager over Pods ?

What is a package manager?

A package manager is a tool that automates the process of installing, upgrading, configuring, and removing a library/ framework.

1. CocoaPods

  • CocoaPods is a centralized dependency manager for Swift and Objective-C Cocoa projects.
  • CocoaPods is based on a main repository called Specs that hosts all the framework specifications. In order to make it available to others, package developers have to push new versions to this repository by using the pod command line.

Advantages

  1. You can search for a dependency on the official CocoaPods website.
  2. Supports both Dynamic Frameworks and Static Libraries

Ref: https://medium.com/ios-os-x-development/cocoapods-vs-carthage-675633e89c3e

2. Carthage

  • Carthage is a decentralized dependency manager for Swift and Objective-C Cocoa projects..
  • Unlike CocoaPods, you don’t have a main Specs repository. This reduces maintenance work and avoids any central points of failure, but project discovery is more difficult. For example, this means that checking for outdated dependencies means checking every dependency repository instead of a single centralized one.
  • While CocoaPods is pretty easy to use, Carthage is more flexible. CocoaPods creates a .xcworkspace file in which all your pods are listed. This makes it easier to use, but also less error proof. If one library fails to build, your whole project doesn’t work. In Carthage you have to add the frameworks you really want to use into your project manually. This means you have to do some extra work, but it also adds a lot more flexibility. Also if you want to get rid off Carthage, you just have to delete the Cartfile and Cartfile.resolved files and the Carthage folder

Disadvantage

  1. The only downside I found about Carthage is that not all frameworks are available for Carthage

Ref: https://github.com/Carthage/Carthage#differences-between-carthage-and-cocoapods

3. Swift Package Manager

  • Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

Ref: https://www.raywenderlich.com/750-an-introduction-to-the-swift-package-manager

6 . readonly external, readwrite internal property ?

Suggested Reading : Access Control

private(set) public var readonlyProperty: Int

Ref:https://stackoverflow.com/questions/25708439/Swift%20readonly%20external,%20readwrite%20internal%20property/25720651

7. Git fork ?

  • A fork is a copy of a repository. Forking a repository allows you to freely experiment with changes without affecting the original project. Most commonly, forks are used to either propose changes to someone else’s project or to use someone else’s project as a starting point for your own idea.

Forking vs cloning

It’s important to note that “forked” repositories and “forking” are not special operations. Forked repositories are created using the standard git clone command. Forked repositories are generally "server-side clones" and usually managed and hosted by a 3rd party Git service like Bitbucket. There is no unique Git command to create forked repositories. A clone operation is essentially a copy of a repository and its history.

Ref: https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow

7. git merge vs rebase

  • The first thing to understand about git rebase is that it solves the same problem as git merge. Both of these commands are designed to integrate changes from one branch into another branch—they just do it in very different ways.

Merge

Merging is a non-destructive operation.

git merge feature master

Rebase

Instead of using a merge commit, rebasing re-writes the project history by creating brand new commits for each commit in the original branch.

git checkout feature git rebase master

Ref: https://www.atlassian.com/git/tutorials/merging-vs-rebasing

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Responses (1)

Write a response