iOS TechnicalInterviewQuestions
iOS TechnicalInterviewQuestions
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.
Big-O notation bir algoritmanın performansını veya time complexity’sini hesaplamak için
kullanılır.
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.
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
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.
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.
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.
So first we will create the protocol in boss view controller. These are like commands that
will given to the 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
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
PUBLIC
It’s recommended to use struct in Swift by default.(THIS IS IMPORTANT)
Structs are helpful in these scenarios, too:
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
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!
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.
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.
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)
PUBLIC
Viewcontroller dan sadece 1 tane olmalı. İki tane varsa memory leak vardır. Bir de
external kütüphaneler var facebookun falan.
PUBLIC