Browse Questions
  • Every UIView has a CALayer that does the actual drawing and compositing.
  • All three transform collections but handle the results differently.
  • Use separate Xcode Schemes, Build Configurations, Bundle Identifiers, and Firebase plists — one set per environment.
  • Encapsulation, abstraction, inheritance, and polymorphism.

Answer: Encapsulation, abstraction, inheritance, and polymorphism. Swift supports all four, though it leans on protocols and value types more than classic class-based OOP languages.

PillarWhat it meansSwift example
EncapsulationHide internal state, expose controlled accessprivate(set) var balance
AbstractionExpose what something does, not howprotocol PaymentProcessor
InheritanceReuse/extend behavior from a base typeclass SavingsAccount: Account
PolymorphismSame interface, different underlying behavior[PaymentProcessor] holding multiple conforming types
protocol PaymentProcessor {
    func charge(_ amount: Decimal) -> Bool
}

class CreditCardProcessor: PaymentProcessor {
    func charge(_ amount: Decimal) -> Bool { /* ... */ true }
}

class PayPalProcessor: PaymentProcessor {
    func charge(_ amount: Decimal) -> Bool { /* ... */ true }
}

let processors: [PaymentProcessor] = [CreditCardProcessor(), PayPalProcessor()]
processors.forEach { _ = $0.charge(9.99) } // polymorphic dispatch