0% found this document useful (0 votes)
5 views

iOS TechnicalInterviewQuestions

Uploaded by

berkay.unal579
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

iOS TechnicalInterviewQuestions

Uploaded by

berkay.unal579
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Technical interview questions

B – Beginner Questions
M – Mid
S – Senior

1. Concurrency(M)
Concurrency is doing more than one task at the same time (parallel). A task is a set of
instructions that accomplish some goal, like downloading an image or refreshing a table.

Concurrency is need to keep the user interface responsive. A common problem that
concurrency solves is a table view of images that just will not scroll properly while the
app is downloading and transforming the images. These are slow non-user interface
tasks that should run somewhere else. And that means concurrency

2. Time complexity(B)
Günümüz bilgisayar dünyasında hız oldukça önemlidir. İşlemler hızlı olmalı ve
kullanıcıya anlık tepkiler verilebilmedir. Bilgisayar dünyasında algoritmalar temel yapı
taşlarındandır. Bu yapı taşlarıda diğer komponentler gibi hızlı ve yavaş
çalışabilmektedir. Algoritmaların hızlarını değerlendirmemiz gerekir. Bir algoritmanın
hızını ise bir süre üzerinden ölçmemiz gerekiyor. Buna da time complexity deniyor.

Time complexity bir algoritmanın çalışması için gerekli olan süredir. Ancak buradaki
süre, saniyeleri hesaplayarak değil, kaç tane işlem gerçekleştirdiğine göre
hesaplanmaktadır. Uygulama tarafından gerçekleştirilen işlem sayısı, veri setinin
büyüklüğüne ve o veri setindeki elemanlarına sırasına göre belirlenir.

Yazılan bir algoritmanın performansını ölçebilmemiz için kullanacağımız en önemli


araçlardan biri ise Big-O notation’dır.

Big-O notation bir algoritmanın performansını veya time complexity’sini hesaplamak için
kullanılır.

Big -O() notationın işlem sayısına göre belirli türleri vardır


Big-O(n) linear ( for loop ile bir arrayin max valuesunu aramak)
Big-O(1) constant (örn arrayin son elemanını getirmek)

Bu notationlar veri seti büyüklüğü arttıkça işlem miktarı nasıl değişir onu temsil ederler

First, the main difference between them is their types. Class is a reference type but
struct is a value type. Due to its reference type properties of the class when a class
instance is copied and assigned to another variable, the new instance will be point to
the same memory location. Because in reference type, they share a single copy of their
data. That means, a change in one of these instances will affect the other one too.

PUBLIC
On the other hand, structs are value type. When we do the same operation, copied the
struct intance and assigned to another variable, the new intances will be point to the
different memory location. Because in value type, they store their data in different point
in memory. So, a change in one of these instances will not affect the other one.

3. Automatic Reference Counting (ARC) in Swift(B)


When a new object is created with Swift, an amount of memory is allocated to
accommodate for that new object. When an object isn’t needed anymore,
it’s deallocated, which frees up space. Allocation and deallocation takes a non-trivial
amount of CPU time and energy.

Memory management is the process of finding what memory can be removed, so RAM
is freed up. It’s a continual process: RAM is used for new data, and that data is removed
when it’s not needed anymore. It’s a problem, of course, when the wrong data is
removed from memory. As an app developer, your job is to write your app in such a way
that memory can be managed (almost) automatically.

Simply said, RAM memory on an iPhone is a limited resource, and when used
efficiently, the user experience on an iPhone is at its best. That’s why, as app
developers, we’re managing memory

On iOS, you use Automatic Reference Counting (ARC) to manage memory

How Automatic Reference Counting Works

 The goal of Automatic Reference Counting is to know which data can be


removed from RAM memory, to free up space.
 An essential concept in ARC is the retain count, which is a number that keeps
track of how many objects are “holding onto” to another object.
 ARC only applies to reference types such as classes, and not to value types
like structs. Value types are copied, so they don’t work with references.

You can already see where the name “Automatic Reference Counting” comes from.
 It’s about references; the link between objects in your code.
 It’s also about counting; keeping track of the number of retains of an object.
 And it’s about automating; you want to spend the least amount of effort on
memory management as a developer.

Every object in Swift – an instance of a class – has a property called retainCount.


 When the retain count is greater than zero, the object is kept in memory
 When this retain count reaches zero, the object is removed from memory

Analogy

PUBLIC
Before we move on, let’s look at an analogy. Imagine a scenario where 3 persons –
Berg, Pete and Sharon – share a piece of paper with a phone number written on it.
We’re calling that piece of paper with the phone number paper. The paper is an
instance of a Swift class, of course.

You can visualize this as 3 persons holding onto a piece of paper, grabbing it with their
hands. It could be the phone number of a pizza place, for example. Berg, Pete and
Sharon all need the phone number for something, so that’s why they’re holding onto
that one shared piece of paper.

At this point, the retain count of paper is 3. Why? Because 3 persons are holding onto
the paper object. This has a consequence: the paper object cannot be removed from
memory, because it’s still in use.

At some point, Sharon doesn’t hold onto the paper with the phone number anymore.
Pete also lets go of paper. They’re done calling the phone number, for example. The
retain count is reduced to 2, and then to 1. Only Berg is holding on to paper. The data is
not yet removed from memory.

Finally, Berg lets go of the piece of paper as well. You can imagine he just forgets he
had it… This reduces the retain count of paper to zero, which promptly removes
the paper object from memory. It’s not needed anymore, so the memory it used is freed
up for other apps.

The variable car_1 is set to nil, so the variable doesn’t hold a reference to
the Car instance anymore. What’s the value of car_2 now?

PUBLIC
The car_2 variable still refers to the Car instance, even though we’ve “nulled”
the car_1 variable. The Car instance is retained in memory and not yet deallocated,
because car_2 is still holding onto it.
Default is strong
 Strong: This is the default, and you don’t use a capture list. Just use the object
in the closure, and you’re good. This works in most scenarios!
 Weak: You use weak to create a weak reference to an object. This will
automatically make that instance optional inside the closure.
 Unowned: Same as weak, except that the referenced instance is not an optional.
You use this when you’re certain the instance cannot become nil.

4. Reference type vs value type


Types in Swift fall into one of two categories: first, “value types”, where each instance keeps
a unique copy of its data, usually defined as a struct , enum , or tuple. The second,
“reference types”, where instances share a single copy of the data, and the type is usually
defined as a class

Give example

Google sheet reference type(class) excel is value type. When I share a google sheet
with you the changes that you did affect my work too. But the excel changes doesn’t
change my work its copy and hold its unique copy of the data

5. Type Methods(B)
Static
Static keyword means it is same for every instance of a type(example: Class).
Also search Static vs Class Difference?

Computed properties(B)
In addition to stored properties, classes, structures, and enumerations can
define computed properties, which don’t actually store a value. Instead, they provide a
getter and an optional setter to retrieve and set other properties and values indirectly.

PUBLIC
6. Delegates(B)
-Boss knows all the information about what
needs to be done intern doesn’t know he is
waiting for the order.

The boss screen will know what did I pick,


and based on the action we will select the
image and colors text and passed that
information to the intern

-And when intern takes that info, he will act


accordingly to info that boss gave him

So first we will create the protocol in boss view controller. These are like commands that
will given to the intern

selectionDelegate is our intern

PUBLIC
Base- Intern side
In here line 24 we are saying; hey “selectionVC” your selectionDelegate(intern) will be
BaseScreen(self)
Then get the commands from the boss and execute in extension

PUBLIC
7. Designated Initializers and Convenience Initializers(B)
Designated initializers are the primary initializers for a class. A designated initializer fully
initializes all properties introduced by that class and calls an appropriate superclass
initializer to continue the initialization process up the superclass chain.

Classes tend to have very few designated initializers, and it’s quite common for a class
to have only one. Designated initializers are “funnel” points through which initialization
takes place, and through which the initialization process continues up the superclass
chain.

Every class must have at least one designated initializer. In some cases, this
requirement is satisfied by inheriting one or more designated initializers from a
superclass, as described in Automatic Initializer Inheritance below.

Convenience initializers are secondary, supporting initializers for a class. You can
define a convenience initializer to call a designated initializer from the same class as the
convenience initializer with some of the designated initializer’s parameters set to default
values. You can also define a convenience initializer to create an instance of that class
for a specific use case or input value type.

PUBLIC
8. What are the differences between class and struct.? Can you list out their pros/
cons in terms of inheritance and mutability, and any possible use cases?

First, the main difference between them is their types. Class is a reference type but
struct is a value type. Due to its reference type properties of the class when a class
instance is copied and assigned to another variable, the new instance will be point to
the same memory location. Because in reference type, they share a single copy of their
data. That means, a change in one of these instances will affect the other one too.

On the other hand, structs are value type. When we do the same operation, copied the
struct intance and assigned to another variable, the new intances will be point to the
different memory location. Because in value type, they store their data in different point
in memory. So, a change in one of these instances will not affect the other one.

While classes are well suited to complex data structures and are passed by reference,
structs are passed by value and better suited to creating simple instances that don't
need inheritance or reference capabilities

Both class and structure can do:

 Define properties to store values


 Define methods to provide functionality
 Be extended
 Conform to protocols
 Define intialisers
 Define Subscripts to provide access to their variables
Only class can do:

 Inheritance(THIS IS ONE OF THE MAJOR DIFFERENCES)


 Type casting
 Define deinitialisers
 Allow reference counting for multiple references.

1. One of the most important differences between structures and classes is that
structures are value types and are always copied when they are passed
around in your code, and classes are reference type and are passed by
reference.
https://stackoverflow.com/questions/24217586/structure-vs-class-in-swift-language?
noredirect=1&lq=1

When Should You Use Structs?

PUBLIC
It’s recommended to use struct in Swift by default.(THIS IS IMPORTANT)
Structs are helpful in these scenarios, too:

o Simple Data Types

Use structs for simple data types. Think about database objects you want
to pass around in your code, like NewsItem, Task or User. Since they’re
so well-defined, and often don’t need to accommodate complex
relationships between objects, it’s simpler to use structs.

o Thread Safety

In a multi-threaded environment, for instance with a database connection


that’s opened in a different thread, structs are safer. They can be copied
from one thread to another thread, without running the risk of a race
condition or deadlock. Classes do not have this inherent safety, unless
they’re deliberately made thread-safe.

o Mostly Structs Scenario

When the properties of a struct are mostly value types too, like String, it
makes sense to wrap them in a struct instead of a class. It’s OK to use
structs within class types, but pay extra attention if you use classes within
struct types. Classes are reference types, so if you’re unaware that your
struct references a shared class instance, and your struct gets copied,
both structs share a reference to that class!

o Don’t Need Inheritance

Structs cannot inherit code from other structs. If you don’t need
inheritance, it’s smarter to use structs (instead of classes). Structs can still

PUBLIC
conform to protocols, and they can be extended, so you still have a few
options for creating flexible, composable code.
Using structs has a huge benefit: it’s easier to reason about data changes
in your code. When a type is a struct, you can be certain that no other part
of your code can hold on to a reference to that struct. Unless it’s explicitly
coded, a struct cannot be changed by some other part of your code.

Classes have a few extra characteristics that structs don’t have:

o Classes can inherit from another class, which you can’t do with structs.
With classes, you can write class MyViewController : UIViewController to
create a subclass of UIViewController. Structs can implement protocols,
can be extended, and can work with generics, though!
o Classes can be deinitialized, i.e. they can implement a deinit function.
Also, you can make one or more references to the same class (i.e.,
classes are a reference type).
o Classes come with the built-in notion of identity, because they’re reference
types. With the identity operator === you can check if two references
(variables, constants, properties, etc.) refer to the same object.

It’s important to note here that you need to use classes if you want to interop
between Swift and Objective-C. If you need Objective-C interoperability, you’ll
need to use classes. For example, if you want to use @objc and dynamic in a
Realm data model, that model needs to be a class.

To summarize, it’s smart to use classes if you need the features that only classes
provide: inheritance, identity, Objective-C interoperability, and scenarios where copying
a value doesn’t make sense.
https://www.appypie.com/struct-vs-class-swift-how-to

PUBLIC
9. Differences between hype and stack memory? (This is related with struct vs class.

But it is a little advanced question)(M)

10. What do we need generics in Swift for? What does keyword associatedtype
and typealias mean to you? (M)
11. What are possible use cases of unowned, weak properties? (You can explain it
in one example.) (B)
12. Swift language has several control flow elements such as guard, defer,
fallthrough etc. What are they and in what situations are you using them
exactly? (B)
13. What are the use cases and differences of following access control keywords:
a) public vs. open (B)
14. What does an optional value mean? (B)
15. SOLİD principles(B)
16. Four pillars of object oriented programming detailed. (Abstraction, encapsulation,
polymorphism, inheritance. (B)
17. What is version control systems(Git)? (B)
18. What is cherry pick commit in git? (B)
19. What is depency injection?(M)
20. What is cocoapods, spm, cartage? (B)
21. Can we add everything to extensions? (B)
Extensions may not contain stored properties.
22. How to handle optional? Optional unwrapping(B)

! = force wrapping, guard let if let, son olarak ?? adını unuttum :D

23. What is typealias? (B)


24. What is property observers(didSet, willSet)? (B)
25. What is lazy? (B)
26. Tuple array, set farkı(B)
27. Generic type(B)
28. Singelton(M)
29. How to construct a view? (B)
Programmatically, .xib or storyboard
30. Mimariler – MVC, MVVM, VIPER(B)
31. ARC – Retain cycle(B)
32. Memory leak nedir, nasıl bulunur? (B)
Bir sayfayı açıp kapattığında ram artıyorsa leak vardır. Ya da Xcode da memory
graph var. Şu ortadaki sembol. Ona tıklayınca memorydeki viewlar gözüküyor. Her

PUBLIC
Viewcontroller dan sadece 1 tane olmalı. İki tane varsa memory leak vardır. Bir de
external kütüphaneler var facebookun falan.

33. Escaping, non-escaping? (B)


34. What is clousure? (B)
35. AnyObject, any class?(M)
36. What is force cast? (B)
37. Hashable? (B)
38. Equatable? (B)
39. Identifable? (B)
40. Associated type?(M)
41. CompactMap, flatMap? (B)
42. Access Control(Private, fileprivate, public) (B)
43. Sorted vs sort (in array) (B)
44. Discardable Result(M)
45. Rethrow(M)
46. Explain URLSession(B)
47. Codable(B)
48. Coding Keys(B)
49. Fastlane
50. Enviroment oluşturma(M)
51. Dictionary vs array vs set(B)
52. Dispatch Group(M)*
53. Dispatch Semifor(M)
54. Concurrency(B)
55. Operation Queue(S)
56. UserDefaults(B)
57. CoreData(B)
58. Promises(M)
59. PromiseKit(M)

For a junior interview: 3,4,8,11,13,14,15,16,17,22,31,32,34,42 numbers are MUST

Others will come probably too.

PUBLIC

You might also like