iOS Developer Interview

iOS Developer Interview

Antonio Palomba (lvl 5)
About Swift

Preview this deck

What is a Polymorphism

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

2

All-time users

2

Favorites

0

Last updated

1 year ago

Date created

Jul 5, 2023

Cards (48)

About Swift

(17 cards)

What is a Polymorphism

Front

In Swift, polymorphism is typically achieved through inheritance and method overriding:
 

class Animal {
    func makeSound() {
        print("The animal makes a sound.")
    }
}

class Cat: Animal {
    override func makeSound() {
        print("Meow!")
    }
}

class Dog: Animal {
    override func makeSound() {
        print("Woof!")
    }
}

// Usage:
let animal: Animal = Animal()
let cat: Animal = Cat()
let dog: Animal = Dog()

animal.makeSound()  // Output: "The animal makes a sound."
cat.makeSound()     // Output: "Meow!"
dog.makeSound()     // Output: "Woof!"
Back

What is a Subscript

Front

Only for Class, allows you to define custom access patterns for instances of a type.

class MyList {
    private var elements: [String] = []

    subscript(index: Int) -> String {
        get {
            return elements[index]
        }
        set(newValue) {
            elements[index] = newValue
        }
    }
}

// Usage:
let myList = MyList()
myList[0] = "Apple"
myList[1] = "Banana"
print(myList[0]) // Output: "Apple"
print(myList[1]) // Output: "Banana"
Back

Why Swift is called a type-safe language

Front
  • Static Type Checking: Swift performs static type checking, which means that the types of variables are checked at compile-time.
  • Type Inference: Swift has a type inference system that can deduce the types of variables based on their initial values.
  • Optionals: Swift introduces the concept of optionals, which allows you to indicate the possible absence of a value.
  • Type Annotations: Although Swift supports type inference, you can also explicitly annotate variable types when necessary.
Back

What is Inheritance and how affects Struct and Class

Front

Classes support inheritance, allowing you to create hierarchies of related classes. A subclass can inherit properties and methods from its superclass and override or extend its behavior. Structs, however, do not support inheritance. They cannot be subclasses or superclasses, making them more suitable for simpler data structures or value-based operations.

Back

What is Encapsulation in Swift

Front

Bundling data and the methods that operate on that data into a single unit called an object.

In Swift, encapsulation is achieved through the use of access control modifiers (public, internal, private, etc.) and the concept of properties and methods within a class or struct.

Back

Which features ONLY a Struct support

Front
  1. Value Semantics: they are copied when assigned or passed as arguments, ensuring independence and immutability.
  2. Default Memberwise Initializers: Structs automatically receive a memberwise initializer for their properties.
  3. Immutable Instances: Structs can be declared as constants (let), making their instances immutable.
  4. Copying and Equatability: Structs support copying through the copy-on-write mechanism and value-based equality comparisons.
Back

Which features ONLY a Class support

Front
  1. Inheritance: allowing one class to inherit properties and methods from another class.
  2. Polymorphism: subclasses can provide their own implementation of superclass methods or properties.
  3. Reference Semantics: Objects created from classes are reference types, allowing multiple references to point to the same instance.
  4. Type Casting: Classes can be type-casted to check their type or to treat them as instances of a different class hierarchy.
  5. Deinitializers: Classes can define deinitializers that are called when an instance is deallocated and no longer in use.
Example of type casting:
class Vehicle {
    var brand: String
    
    init(brand: String) {
        self.brand = brand
    }
}

class Car: Vehicle {
    var model: String
    
    init(brand: String, model: String) {
        self.model = model
        super.init(brand: brand)
    }
}

struct ContentView: View {
    var body: some View {
        let vehicle: Vehicle = Car(brand: "Tesla", model: "Model S")
        
        if let car = vehicle as? Car {
            Text("Brand: \(car.brand)\nModel: \(car.model)")
        } else {
            Text("Unknown vehicle type")
        }
    }
}
Back

What is Mutability for Struct and Class

Front

Struct is value type while a class is reference type, so when you create an instance of a struct, it is copied, and each copy is independent of the others. Modifications to one copy do not affect the others. In contrast, when you create an instance of a class, multiple references can point to the same instance. Modifying one reference will affect all other references to that instance.

Back

Explain to me that I do not know anything, what is Swift

Front

Swift is a modern multi-paradigm (OOP and POP) programming language that was introduced by Apple in 2014.

Back

Which features a Class and Struct support

Front
  1. Properties: to store values and provide accessors and modifiers for those values. They can define computed properties with getters and setters, allowing the computation of property values on the fly.
  2. Methods: to perform operations and behaviour.
  3. Initialisers: to set up the initial state of instances.
  4. Subscripts: to provide access to values using subscript syntax.
  5. Extensions: to add new functionality, including properties, methods, and initializers.
  6. Conformance to Protocols: defining conformance to a set of requirements and enabling code reuse.
  7. Access Control: to regulate their visibility and accessibility.
Back

What is the difference in Identity and Comparisons between Struct and Class

Front

Classes have identity, meaning that two class instances with the same property values are considered different objects. You can compare class instances using reference equality (=== and !==). Structs, on the other hand, do not have identity. Two struct instances with the same property values are considered equal, and you compare them using value equality (== and !=).

Back

What is the difference in Memory Management between Struct and Class

Front

Classes in Swift use Automatic Reference Counting (ARC) to manage memory. ARC keeps track of references to class instances and automatically deallocates them when they are no longer referenced. Structs, being value types, are automatically managed by the compiler, and memory management is handled implicitly.

Back

Why Swift is POP

Front

Protocols in Swift define a set of methods, properties, and other requirements that a type can adopt. A type can conform to one or multiple protocols, providing a way to express reusable behavior and create flexible code. Protocols in Swift can be used to achieve composition, reusability, and extensibility.e

Back

Why using @StateObject instead of @ObservedObject

Front

StateObject was introduced in Swift due to memory-leak issue caused originally by ObservedObject. The problem was caused by the deinitialization of a class instantiated with ObservedObject not deallocated from memory in a correct way when multiple instance of it where created inside code.

Back

What is the main difference between Struct and Class

Front

Struct is value type while a class is reference type

Back

Why Swift is a multi-paradigm programming language

Front

Swift is a multi-paradigm programming language that supports both object-oriented programming (OOP) and protocol-oriented programming (POP) paradigms.

Back

What are Interfaces in Swift

Front

In Swift, interfaces are defined using protocols. A protocol defines a blueprint of methods, properties, and other requirements that a class, struct, or enum must adhere to.

Back

About Version Control

(8 cards)

What is Centralised Workflow

Front

In this workflow, a single "master" branch serves as the central repository. Developers clone the repository, make changes in their local branches, and push their changes to the central repository. It's a simple workflow suitable for small teams or projects.

Back

What is Gitflow Workflow

Front

This workflow defines a specific branch structure, consisting of a "master" branch for stable releases, a "develop" branch for ongoing development, and feature branches for individual features or tasks.

Back

What is Git

Front

Git is a distributed version control system (DVCS) widely used for managing source code and tracking changes. It was created by Linus Torvalds, the creator of Linux

Back

What is git and github

Front

Git is a software maintained by linux while GitHub is a service owned by Microsoft.

Back

What is Git Workflow

Front

Git workflow refers to a set of guidelines and practices that outline how a team collaborates on a project using Git version control system.

Back

What are Atomic Commits

Front

It’s a software development practice where changes to a codebase are divided into small, self-contained units that can be independently committed.

Back

What is Version Control

Front

Is a system that allows multiple people to collaborate on a project while keeping track of changes made to the project's files over time.

Back

What is Feature Branch Workflow

Front

Each new feature or task is developed in a dedicated branch. Developers create a new branch from the "master" or "develop" branch, make their changes, and merge the branch back into the main branch.

Back

About SOLID

(6 cards)

What is I of SOLID

Front

Interface Segregation Principle (ISP): Clients should not be forced to depend on interfaces (protocols) they do not use. This principle promotes the idea of segregating interfaces (protocols) into smaller, more focused ones.

  • Advantage: avoid creating dependencies and bloated interfaces (protocols).
protocol Vehicle {
    var brand: String { get set }
    var model: String { get set }
    var year: Int { get set }
    var color: String { get set }
    
    func start()
    func stop()
    func accelerate()
    func brake()
    func turnLeft()
    func turnRight()
    func switchLights(on: Bool)
    func adjustSeat(position: Int)
    func playMusic()
    func lock()
    func unlock()
    // ... many more methods
}
/// THIS SHOULD BE AVOIDED, TOO MANY UNRELATED FUNCTIONS
Back

What is O of SOLID

Front

Open-Closed Principle (OCP): Software entities (classes, modules, functions) should be open for extension but closed for modification.

  • Advantage: Increase adaptability of the codebase.
protocol Shape {
    func area() -> Double
}

struct Rectangle: Shape {
    let width: Double
    let height: Double
    
    func area() -> Double {
        return width * height
    }
}

struct Circle: Shape {
    let radius: Double
    
    func area() -> Double {
        return Double.pi * radius * radius
    }
}

struct AreaCalculator {
    func calculateTotalArea(shapes: [Shape]) -> Double {
        var totalArea: Double = 0.0
        for shape in shapes {
            totalArea += shape.area()
        }
        return totalArea
    }
}

// Usage:
let rectangle = Rectangle(width: 5.0, height: 3.0)
let circle = Circle(radius: 2.5)

let areaCalculator = AreaCalculator()
let totalArea = areaCalculator.calculateTotalArea(shapes: [rectangle, circle])

print("Total area: \(totalArea)")

/// ADDING A NEW SHAPE LIKE A TRIANGLE DOES NOT CHANGE WHAT AreaCalculator DOES. SO AreaCalculator FOLLOW THE PRINCIPLES OCP
Back

What is D of SOLID

Front

High-level modules should depend on abstract interfaces or contracts rather than concrete implementations.

  • Advantage: helps to decouple modules, improve flexibility, and facilitate easier testing and maintenance.
protocol Notification {
    func send(message: String)
}

class EmailNotification: Notification {
    func send(message: String) {
        print("Sending email notification: \(message)")
    }
}

class SMSNotification: Notification {
    func send(message: String) {
        print("Sending SMS notification: \(message)")
    }
}

class NotificationService {
    private let notification: Notification
    
    init(notification: Notification) {
        self.notification = notification
    }
    
    func notifyUser(message: String) {
        notification.send(message: message)
    }
}

// Usage:
let emailNotification = EmailNotification()
let smsNotification = SMSNotification()

let notificationService1 = NotificationService(notification: emailNotification)
notificationService1.notifyUser(message: "Hello, this is an email notification")

let notificationService2 = NotificationService(notification: smsNotification)
notificationService2.notifyUser(message: "Hello, this is an SMS notification")
Back

What is SOLID

Front

SOLID is an acronym that represents a set of five design principles for writing clean, maintainable, and scalable object-oriented software. These principles were introduced by Robert C. Martin (also known as Uncle Bob).

Back

What is L of SOLID

Front

Liskov Substitution Principle (LSP): Subtypes must be substitutable for their base types.

  • Advantage: avoid unexpected behaviours and logical errors
class Animal {
    func makeSound() {
        // Default implementation
    }
}

class Dog: Animal {
    override func makeSound() {
        print("Woof!")
    }
}

class Cat: Animal {
    override func makeSound() {
        print("Meow!")
    }
}

func makeAnimalSound(animal: Animal) {
    animal.makeSound()
}

// Usage:
let dog = Dog()
let cat = Cat()

makeAnimalSound(animal: dog) // Output: "Woof!"
makeAnimalSound(animal: cat) // Output: "Meow!"

/// IN THIS CASE makeAnimalSound USE Animal AS AN ACCEPTED TYPE AND NOT Dog OR Cat
Back

What is S of SOLID

Front

Single Responsibility Principle (SRP): A class should have only one reason to change.

  • Advantage: By separating responsibilities, classes become more focused, easier to understand, and less likely to be affected by changes in other parts of the system.
class UserManager {
    func createUser(username: String, password: String) {
        // Code for creating a user and persisting it to a database
        // ...
        print("User created: \(username)")
    }
    
    func authenticateUser(username: String, password: String) {
        // Code for authenticating a user
        // ...
        print("User authenticated: \(username)")
    }
    
    func deleteUser(username: String) {
        // Code for deleting a user from the database
        // ...
        print("User deleted: \(username)")
    }
}

// Usage:
let userManager = UserManager()

userManager.createUser(username: "john123", password: "password123")
userManager.authenticateUser(username: "john123", password: "password123")
userManager.deleteUser(username: "john123")

/// So every time we call a function we only change the calss for a specific reason
Back

About Agile

(6 cards)

What is Scrum

Front

Scrum is an Agile framework for managing complex projects.

Back

What are the Artifacts in Scrum

Front
  • Product Backlog: A prioritized list of requirements, features, or user stories that represent the work to be done. It is managed by the Product Owner and serves as the single source of truth for the project.
  • Sprint Backlog: A subset of items from the Product Backlog that the Development Team commits to completing during a sprint.
  • Increment: The sum of all completed Product Backlog items in a sprint, providing a tangible, potentially shippable deliverable.
Back

What are the Roles in Scrum

Front
  • Product Owner: the stackholder
  • Scrum Master: Facilitator and assigning tasks
  • Development Team: cross-functional group responsible for delivering the product increment
Back

What is a project

Front

A temporary effort that a person or a team make to reach a common goal.

Back

What are the Events in Scrum

Front
  • Sprint Planning
  • Daily Scrum
  • Sprint Review
  • Sprint Retrospective
Back

What is Agile

Front

Agile methodology is an iterative and flexible approach to project management and software development that emphasizes collaboration, adaptability, and continuous improvement.

Back

About Design Patterns

(7 cards)

What’s the difference between the Controller and ViewModel

Front

The Controller in MVC focuses on managing user input, updating the Model, and selecting the appropriate View. On the other hand, the ViewModel in MVVM acts as a data converter and presenter, providing data and behaviour to the View while abstracting the underlying Model.

Back

What are MVC, MVVM and MVVM-C

Front

Architectural Design Patterns

Back

How MVVM-C works

Front

The Coordinator in MVVM-C controls the flow between different ViewModels and coordinates the navigation stack. It helps separate the navigation logic from the ViewModel, allowing for better organization and testability.

Back

How MVC works

Front

MVC aims to achieve a clear separation of concerns, where each component has a specific responsibility.

  • The Model encapsulates data and business logic,
  • The View is responsible for displaying the UI,
  • The Controller manages the interaction between the Model and the View.
Back

How MVVM works

Front
  • ViewModel exposes data and commands that the View binds to.
  • The View updates its state and appearance based on changes in the ViewModel.
  • The ViewModel, in turn, communicates with the Model to fetch data, perform business logic, and update the Model if necessary.
Back

What is a Design Pattern

Front

A design pattern is a general reusable solution to a commonly occurring problem in software design.

Back

What other Design Patterns you know

Front
  1. Singleton Pattern: Ensures that a class has only one instance and provides a global point of access to it.
  2. Factory Pattern: Provides an interface for creating objects, allowing subclasses or implementing classes to decide the concrete type to instantiate.
  3. Builder Pattern: Separates the construction of complex objects from their representation, allowing the same construction process to create different representations.
  4. Adapter Pattern: Allows objects with incompatible interfaces to work together by converting the interface of one class into another interface that the clients expect.
  5. Observer Pattern: Defines a one-to-many dependency between objects, so that when one object changes state, all its dependents are notified and updated automatically.
Back

About REST APIs

(4 cards)

What are the main response code for REST APIs operations

Front

REST APIs use HTTP status codes to indicate the outcome of a request. For example, 200 OK indicates a successful request, 404 Not Found means the requested resource was not found, and 500 Internal Server Error indicates a server-side error.

Back

Which kind of authorisation you can use to access to Rest API

Front
  1. API Key: Unique identifier for API access.
  2. OAuth: Secure framework for user resource access.
  3. Basic Auth: Simple authentication with username and password.
  4. Bearer Token: Access token sent in API headers.
  5. JSON Web Tokens (JWT): Self-contained token for user authentication.
  6. Digest Auth: Secure credentials with challenge-response mechanism.

OAuth is generally preferred for its flexibility, security, and ability to grant limited access to specific resources.

Back

What are the common HTTP Verbs used with REST APIs

Front
  • GET: Retrieve a representation of a resource.
  • POST: Create a new resource.
  • PUT: Update an existing resource.
  • DELETE: Delete a resource.
Back

What are REST APIs

Front

REST (Representational State Transfer) is an architectural style for designing networked applications.

REST APIs (Application Programming Interfaces) are a set of rules and conventions that allow systems to communicate and exchange data over the internet using the principles of REST.

Back