Tur Flashcards
(160 cards)
What is the difference between copy and retain?
- both relates to memory management and object references in Objective-C (particularly)
- retain increases the retain count of an object (thanks to ARC we don’t have to manually retain/release)
- copy creates a new independent instance of an object
Explain code signing.
- security mechanism used by Apple to ensure that only trusted apps run on iOS devices.
- It involves cryptographically signing your app’s executable and other resources before they can be installed and run on an iOS device.
- ensuring the app hasn’t been tampered by malicious entity
- _CodeSignature + embedded.mobileprovision
Explain iOS app lifecycle.
- NotRunning
- Inactive (NotRunning -> UIApplicationDidFinishLaunching , Active -> UIApplicationWillResignActive)
- Active (Inactive -> UIApplicationDidBecomeActive,
Background/Suspended -> UIApplicationWillEnterForeground) - Background (Active -> UIApplicationDidEnterBackground)
- Suspended (UIApplicationWillTerminate -> NotRunning)
Explain the difference between background, suspended and not-running (terminated) app states.
- when the user sends app to the background it goes to the background state
- in background state the application is inactive, but may execute code (either finite current task, or perform some background tasks – permissions required).
- after finishing background tasks, the application goes to the suspended state and cannot execute code.
- when OS needs more memory, it may kill the suspended app.
Describe Swift language, outline its advantages and disadvantages.
- strongly-typed
- supports multiple paradigms
- static typing
- generics, protocols, optionals, etc..
- concurrency checking in Swift 6 for data-race free applications
- Swift is available on multiple platforms (AppleOS’s/Linux/Windows)
- Swift compiler is based on LLVM
[Architecture] Explain MVC.
.
[Architecture] Compare delegate and KVO patterns.
- both patterns are to provide communication between objects
- delegation creates one-to-one relationship, it is protocol-based
- KVO creates many-to-many relationship where messages are broadcasted and all subscribes are being notified
Explain protocols to a junior developer.
- protocols define blueprints of methods, properties and other requirements that a conforming type must implement
- they enable polymorphism and abstraction in a type-safe manner
Explain POP to a junior developer.
- a specialized version of the OOP
- popularized in Swift development
- extends polymorphism to value-types
- it is more lightweight and cleaner way to design reusable code
- ## alternative to a hierarchy of classes via inheritance
What static typing brings to the swift language?
- type safety (errors caught at compile time)
- performance (reduced runtime overhead thanks to generic specialization)
- compile-time optimization (because types are fully known at compile time)
- expressiveness
[Generics] How to explicitly specialize a generic function in Swift?
- we need to pass the type explicitly to a function
- explicit specialization is a process where you explicitly specify a type of a generic function at a call site.
Explain Generic Specialization to a junior developer.
- swift compiler feature
- creates type-specific versions of generic methods that are actually in use (previously resolved what set of specialized methods is needed)
- to avoid runtime type checks
- depends on optimization compiler’s flag (will be turned off with -Onone) and wholeModuleOptimization
- happens during SILGen/SILOptimizationPasses compilation stages
Explain inlining.
.
Describe compiler’s optimization flags
-O
-O2
-O3
-Onone
-Osize
Describe WMO (Whole Module Optimization)
.
[Generics] Explain generic type constraints.
.
[SwiftConcurrency] What does it mean that a type is Sendable?
- when a type conforms to the Sendable protocol it can be safely passed across concurrency boundaries (tasks, threads)
- it is guaranteed by the compiler that this type will not introduce data races when passed between concurrent contexts
What is the difference between Sequence and Collection?
- sequence protocol represents a series of values that can be iterated over one at a time
- collection protocol represents a finite, repeatable, and random-access group of elements
What are phantom types and when would you use them?
- Phantom Type to typ obecny w deklaracji generics, ale niewystępujący w runtime.
- Używany do zapewnienia większego bezpieczeństwa typów, wprowadzania ograniczeń i rozróżnienia semantycznego typów.
- Jest przydatny w modelowaniu stanów, systemach uprawnień i API, gdzie poprawność kolejności operacji lub rozróżnienie kontekstów jest kluczowe.
- przykład z modelowaniem grup krwi
Is it possible to have a type with non-throwing method that is satisfying a throwing protocol method?
- yes, it is possible
- however, we will still need to call it with try when dealing with the abstraction
- when dealing with that particular type, we don’t need to call it with try
[Generics] Explain conditional conformances in Swift?
- with conditional confromances we can make a generic type conform to a protocol under certain conditions (via type-constraints)
- it is useful for making recursive design
- some built-in generics uses conditional conformances in that way - e.g. an Array of Encodables is also Encodable
[Generics] Explain generics and how we can use them?
- generics enable you to write functions, protocols, classes, actors, structures, or enums that can work with any type, while still maintaining type safety
- it is a very powerful feature that enables you to write reusable and robust code
- especially in combination with generic type constraints, conditional conformances, specialized protocols
- many Swift standard library features are generic, like Array, Dictionary, and Optional
- however, we should not overuse generics, as it makes code more complex to understand
- avoid premature generalization and always start with specialized code
- everything is a trade-off
Explain local reasoning and locality of behaviour.
- writing clean code, minding encapsulation, immutability, value semantics, etc.. so anybody may understand the logic without knowing the wider context of the system.
- LoB - good modularization - simmilar/cooperating functionalities should be close together.
Explain the difference between throws and rethrows.
- a rethrowing function is the function that only rethrows errors from functions that were passed to that function as arguments and cannot throw any other (own) errors
- in order to throw own errors, the function must be marked as throws