ios_interview_2025_03_23_183554 Flashcards

(31 cards)

1
Q
  1. What are the main differences between Structs and Classes in Swift? When would you use one over the other?
A

Structs are value types, meaning they are copied when assigned or passed to a function, while Classes are reference types, meaning they share the same instance across different references. Use structs when immutability and thread safety are important (e.g., model data) and classes when you need shared state or object identity (e.g., ViewModels, service layers).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. Explain ARC (Automatic Reference Counting) in Swift. How do retain cycles happen, and how can you avoid them?
A

ARC automatically manages memory by increasing and decreasing reference counts for objects stored in the Heap.
Stack stores local variables and structs, releasing memory automatically when the scope ends.
Heap stores class instances, requiring ARC to control their lifecycle.
Retain cycles occur when two objects in the Heap hold strong references to each other, preventing deallocation. To avoid this, use weak or unowned references in closures or the delegate pattern.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are property wrappers in Swift? Can you give some examples?

A

Property wrappers add custom logic around property storage. Examples:
@State (SwiftUI state management)
@Published (observable properties in Combine)
@AppStorage (UserDefaults storage)Use them to simplify property behaviors and encapsulate logic.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you handle state management in SwiftUI?

A

SwiftUI provides different tools for state management:
@State for local state within a view
@StateObject for reference-type objects owned by a view
@ObservedObject for external observed objects
@EnvironmentObject for global dependencies

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the difference between async/await and GCD (Grand Central Dispatch)?‬
‭ When would you choose one over the other?‬

A

Async/await provides structured concurrency, making asynchronous code easier to read‬
‭ and maintain. GCD provides fine-grained control over queues and threading. Use‬
‭ async/await for clean, sequential async tasks and GCD when managing complex‬
‭ concurrency (e.g., low-level threading optimizations).‬

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Can you explain the main differences between SwiftUI and UIKit in terms of‬
‭ rendering, performance, and lifecycle?‬

A

SwiftUI is declarative, using a diffing system for rendering, whereas UIKit follows an‬
‭ imperative approach with a view hierarchy. SwiftUI is generally more efficient for UI updates‬
‭ but has fewer customization options than UIKit. UIKit provides more control over lifecycle‬
‭ and event handling.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How would you design a networking layer in an iOS app? What are best practices‬
‭ for handling API requests?‬

A

‭ A well-structured networking layer should include an‬‭ APIClient‬‭ using‬‭ URLSession‬‭ (or‬
‭ Alamofire), models for request/response parsing, and error handling. Use dependency‬
‭ injection for testability and adopt Combine or async/await for handling responses.‬

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

‬What strategies do you use for dependency injection in iOS applications?‬

A

Strategies include initializer injection (preferred for testability), property injection (used for‬
‭ optional dependencies), and service locators (less preferred due to hidden dependencies).‬

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you debug memory leaks in iOS applications?‬

A

‬ Use Xcode’s Instruments (Leaks & Memory Graph Debugger) to analyze retain cycles.‬
‭ Utilize weak references in closures and properly deallocate objects to prevent leaks.‬

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are some ways to optimize the performance of a SwiftUI-based app?

A

Avoid excessive view recomputation, use‬‭ @StateObject‬‭ instead of‬‭ @ObservedObject‬
‭ when needed, optimize lists with‬‭ @Identifiable‬‭ , and‬‭ leverage‬‭ LazyVStack‬‭ and‬
‭ LazyHStack‬‭ for better performance.‬

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the trade-offs between using MVVM vs. VIPER vs. Redux-style state‬‭ management?‬

A

MVVM is simpler and easier to adopt but can lead to bloated ViewModels. VIPER enforces‬
‭ better separation of concerns but increases complexity. Redux provides unidirectional data‬
‭ flow but requires careful state management.‬

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How would you design an offline-first mobile app that syncs data when online?‬

A

‬‭ Use Core Data or Realm for local storage, implement background sync tasks, use conflict‬ resolution strategies, and track sync states efficiently.‬

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

If you had to scale an iOS app to support millions of users, what factors would you‬‭ consider?‬

A

Optimize networking with caching and pagination, use background processing for heavy‬‭ tasks, adopt efficient data storage strategies, and monitor performance with analytics tools.‬

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

‭ Can you walk me through your most challenging project as an iOS developer?‬

A

‬‭ M-payment Getnet‬

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Tell me about a time you had to work under a tight deadline. How did you handle it?‬

A

‬‭ Mention Xmas Hub, negotiation MVP‬

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

‭ Have you ever disagreed with a technical decision in your team? How did you resolve‬‭ it?

A

Of course, never‬‭ considered any as a problem, everything in that matter is solved by‬ conversations, rising pros and cons. Sometimes decisions are top down and we just need to‬‭ live with them doing the best we can with we are given‬

17
Q

‬‭ How do you approach mentoring junior developers?‬

A

‭ For me, patience is the key. they will require assistant, they will ask questions that may‬‭ sound obvious but having in mind that is a process. I don’t usually like to give all at once, I‬‭ help unlock when something isn’t progress but like to see them try even if it;s not always the‬‭ best approach but is trying that we grow, by right or wrong.‬

18
Q

‭ Describe a time when you had to handle multiple priorities at once. How did you‬‭ manage them?‬

A

Delegating in those situations is the best approach, if you can of course, otherwise, it must‬‭ be raised that not always can be done at the same time for one person without the help and‬‭ prioritise…

19
Q

‬‭ Tell me about a time you had to debug a critical issue in production. How did you approach it?‬

A

First try to get the device info, OS version, app version and steps to reproduce, then start investigating‬‭ adding breaking points to points of interest‬

20
Q

‬‭ How would you explain memory management in Swift to a junior developer?‬

A

‬I could use the analogy to google spread sheet (class) and sending a microsoft excel sheet file‬‭ through email(struct) and then explain from that the concept of class and struct and use this link to‬‭ explain ARC.‬

21
Q

‬‭ Describe a time when you received negative feedback. How did you handle it?‬

A

‬If constructive, understand the points, take notes ask for suggestions for other peers and make a‬ “roadmap” to improve my weak points‬

22
Q

‬‭ How do you ensure effective communication in a remote or distributed team?‬

A

‬Being available in core hours, if text is not being effective go for a quick call and being sure at the end‬‭ the message was understood.‬

23
Q

‬‭ What steps do you take when onboarding into a new project or codebase?‬

A

Taking time to understand the working process, read the code to understand architectures,‬‭ components, reausability, testing procedures, reading MRs, then picking up smaller questions at‬‭ beginning if possible to put in action what I’ve been learning‬

24
Q

Explain retain cycles in more depth. What’s the difference between weak and unowned?

A

weak references allow objects to be nil (typically used for delegate patterns).
unowned references assume the object will always exist, avoiding optionality (used
when one object outlives another).

25
7. How would you optimize an iOS app’s memory usage for large lists?
LazyVStack or LazyHStack
26
What are protocol extensions in Swift, and how do they differ from regular extensions?
Protocol extensions allow adding default method implementations without modifying existing conforming types.
27
What is the difference between escaping and non-escaping closures?
Escaping closures outlive the function (e.g., used in async tasks). Non-escaping closures are executed before the function ends.
28
How do you handle authentication securely in an iOS app?
Use OAuth 2.0 and JWT for secure authentication. Store tokens securely using Keychain.
29
How do you handle real-time data updates in an iOS app?
WebSockets for real-time communication. Combine with Publishers for reactive updates. Polling as a fallback strategy.
30
Explain how UIKit’s Auto Layout differs from SwiftUI’s layout system.
Auto Layout uses constraint-based positioning, while SwiftUI follows a declarative layout model, automatically recalculating views based on data changes.
31
What are your strategies for handling app modularization?
Use Swift Package Manager for separating business logic. Adopt feature-based modularization (e.g., Core, UI, Networking). Define clear module boundaries to improve testability and maintainability.