Interview Questions CheatSheet for Junior iOS Developers

React Dojo
7 min readAug 17, 2017

Hi, I’m Saaya! So we’ve all studied programming, I get that. But so we really know how to smartly and shortly answer questions when asked?

So that’s it, this is a cheat sheet for answering basic programming in iOS. It is swift-based, but there are some questions about objective-c. Adding more! Hope it helps ya’ll.

1. What is swift? Explain some features

Swift, a modern programming language, was announced by Apple Inc. in June 2014.

  • Fast (static dispatch for methods)
  • Safe (type safe)
  • Friendly syntax (more concise than objective-c)

Some key features unique and powerful are generics, tuples, closures and type inference, optional.

2. What are your favourite iOS blogs? (up to you)

Bob the Developer https://blog.bobthedeveloper.io/why-i-had-to-say-goodbye-to-medium-after-having-blogged-for-one-year-4d967569388a

raywenderlich.com https://www.raywenderlich.com/

NSHipster http://nshipster.com/

AppCoda http://www.appcoda.com/

3. What is the difference between static typing and dynamic typing?

Swift is using Static typing, which is able to give you a compiler error. Objective-C is using dynamic typing, where it performs type checking at run-time. This means that code can compile even if they contain errors that will prevent the script from running properly.

4. What is type inference?

A feature that enables the compiler to automatically set the data type on a variable without setting the data type, by looking at the value.

5. What is generics?

A type that can take in any type. It is type-safe, meaning that the compiler will complain at compile time. For instance, if you pass a string as a generic type and use it as an integer, there will be a compile-time error. This is good because you can detect errors beforehand.

6. Can objects be nil in Objective-c and Swift?

In Objective-c, any object can be nil. In swift, only Optionals can be nil

7. What are protocols?

Protocol is an interface, meaning that they contain abstract methods, constants and variables. Protocols enable shared functionality across classes. You can implement multiple protocols.

8. What are tuples?

Because they are value types, they are like an immutable array, but the way declared and read is different. They are useful when you want to have multiple return types.

var person = ("Saaya", "Age is secret") 

var firstName = person.0 // Saaya
var lastName = person.1 // Age is secret

To declare, you need a parenthesis (), and to access, you need to give a (.)dot notation.

func getTime() -> (Int, Int, Int) {
return ( hour, minute, second)
}
var times = getTime()

9. How is mutability achieved in swift and objective-c?

In swift, a constant is a constant, and a variable varies. The mutability is defined when initializing a variable with a keyword, is not defined by a data class.

In objective C, mutability is limited by certain classes. For instance, you have to use the NSMutableArray type to be able to change the array size.

10. What are subscripts?

Subscripts are shortcuts for accessing the member elements of a collection, list, or sequence.

11. What is the difference between Any Object and Generics?

AnyObject does not specify any type, so it will let you pass any type, which might end up in a run-time error(which is bad). When you use generics, you need to specify a type, so it will not let you pass if you input the wrong type at compile-time(which is good).

12. What is an optional?

Optional is a type that can store nil value. When it stores a value, it wraps around the value. In order to get the value wrapped in an optional, you need to unwrap it.

13. Write 3 ways to unwrap an optional

  • if-let unwrapping (safe unwrapping)
var myString:String?

if myString != nil {
print("Value exists!")
}else {
print("Nil value")
}
  • guard-if unwrapping (also safe)
var someStr: String?
guard if unwrapped = someStr else { return }
Print (unwrapped)
  • forced unwrapping (use only when 100% sure there is value)
var someStr: String?
Let unwrapped3 = someStr!

14. What is the difference between Struct and Class?

Structs are value types, while classes are reference types.

15. Name two types of data structure for memory allocation

Stack and heap memory

16. What is the difference between stack and heap memory?

Stack is a simple FIFO(first-in-first-out) memory structure. Stack is always used to store the following two things: The reference portion of reference-typed local variables and parameters and the Value-typed local variables and method parameters.

Heap memory has non-lined random objects stored in the memory. The advantage is that it allows objects to be allocated or deallocated in random order. This will require you to use garbage collector functions to free the memory though.

In heap memory, the following is stored: the content of reference-typed objects.

17. What are closures?

Self-contained functions are organized as blocks. They can be passed around and nested. You can pass a closure as an argument of a function or you can store it as a property of an object.

18. (objective-c) What is type id?

It is a pointer to any type in objective-c. (Like Any in swift) Because it can store any type, there will be no compile error and you can later cast it to another type.

19. (Objective-c)What happens when you invoke a method on a nil pointer in Objective-C?

It is treated as a no-op(no operation). It will just execute the next instruction. This not an error, and it will just return nil or 0.

20. (Objective-c)What is the difference between NSArray and NSMutable array?

NSArray is used when you don’t want to change the size or data stored in the array. In NSMutable array, you can add, delete or change values in an array.

21. What is dynamic method resolution?

Calling dynamic typing at a compile-time.

22. What are the two ways to pass data from one ViewController to another?

By segue and delegate pattern.

23. What is an in-and-out parameter? How do you use &(ampersand) in this parameter?

If you use an extra “inout” keyword in a parameter, the original value passed in the parameter will be changed, once the function is executed.

func swapTwoInts(_ a: inout Int, _ b: inout Int) {   let temporaryA = a
a = b
b = temporaryA
}

In this function, the values of a and b are swapped.

var someInt = 3
var anotherInt = 107
swapTwoInts(&someInt, &anotherInt)
print("someInt is now \(someInt), and anotherInt is now \(anotherInt)")
// Prints "someInt is now 107, and anotherInt is now 3"

Once executed, you can see that the original values have been changed.

24. Explain the MVC pattern

It is a short abbreviation for Model-View-Controller. It is a program design patter where the application is composed of these three parts.

25. What is GCD? How is it used?

It is a framework provided by apple that deals with multiple threads. It is used when you want to work with asynchronous tasking. For instance, when you want to fetch data from API, you can used GCD to do fetch tasks asynchronously.

26. What is the difference between synchronous and asynchronous tasking?

In synchronous tasking, one task doesn’t start until another is finished. In asynchronous tasking, tasks are executed concurrently.

weak var name: String?

27. What is auto layout?

It is a system in xCode that dynamically calculates the size and position of all the views based on constraints placed on those views.

28. What is Core Data? What is the benefit?

A native data storage provided by apple enables persistent / permanent storage. It is easy to manage because you can use xcode to change Model name or attributes. It is native so it is very easy to update.

29. Difference and frame and bounds.

The bounds of a UIView is the location(x,y) and width(x,y) itself, but the frame of the UIView refers to the superview that UIView is contained.

30. What is a singleton?

A design pattern in programming where you can use only one instance for a class. This instance is called “shared instance”. Example:

class Manager{
static let sharedInstance = Manager()
}
Manager.sharedInstance

31. What is a design pattern?

They are solutions to programming problems, like a template of OOP implemented at the correct situation.

32. What is the three basic kind of design patterns?

  • structural
  • creational
  • behavioral

33. What is a delegate pattern?

A delegate is an object that acts on behalf of, or in coordination with, another object when that object encounters an event in a program.(apple)

34. What is a category in swift?

Categories is an Objective-c term for extension in swift. Basically you can extend the closure outside of the class. In objective-c, you need to name the extension/category

35. What is retain cycle?

Retain cycle is the memory structure where strong references of objects are pointing to each other and memory can’t be deallocated. This happens because each object’s reference is lost, but the reference counter still exists.

36. What is a memory leak?

Memory that can’t be deallocated. An outcome due to the cause of retain cycle, or forgetting to deinitializing instances.

37. What is ARC?

Short for Automatic Reference Counter, a memory manager provided in swift. Also defined as garbage collector. What it does:

  • releases memory space used as instances that are no longer needed.
  • memory is allocated when classes are initialized or de-initialized.
  • keeps track of currently referring class instances (reference count)

38. What is the difference between strong and weak?

When you reference an object, it is strong by default in swift. In a strong reference, ARC counts the references for each instances made. This happens when a parent references a child.

To make a weak reference, you need to declare with the weak keyword. Weak is used when a child wants to reference a parent. This is to prevent retain cycle.

39. Which is faster? Array and Set?

Set is faster to search because there is only one unique object in the collection. You can directly search for the value in a set, but you have to iterate through the values in an array.

40.(Objective-c)What is the difference between @synthesize and @dynamic?

@synthesize generates getter and setter for you property, @dynamic tells the compiler that getter and setters are implemented somewhere else(like subclass).

--

--

React Dojo

React Tips and Learning Materials, Front-End Developing, Graphic and UI/UX Design