Browse Questions
  • Use Secure Message when two parties with separate key pairs exchange data, and Secure Cell when a single party encrypts data for itself.
  • A memory leak is memory that is allocated but never freed — usually from retain cycles.
  • The Factory pattern creates objects without exposing the creation logic.
  • Secure Comparator is a zero-knowledge protocol that lets two parties confirm they hold the same secret without either side transmitting it, or leaking anything usable when the secrets differ.

Answer: The Factory pattern creates objects without exposing the creation logic. The caller asks for an object and gets one back — without knowing which concrete type was created.

Code Example:

// Simple factory function
enum Environment { case dev, staging, production }

struct NetworkClientFactory {
    static func make(for environment: Environment) -> NetworkClientProtocol {
        switch environment {
        case .dev:
            return MockNetworkClient()
        case .staging:
            return NetworkClient(baseURL: "https://staging.api.com")
        case .production:
            return NetworkClient(baseURL: "https://api.com")
        }
    }
}

// Caller doesn't care which type comes back
let client = NetworkClientFactory.make(for: .production)

// Factory method on a protocol
protocol ViewControllerFactory {
    func makeLoginViewController() -> UIViewController
    func makeHomeViewController() -> UIViewController
}