Persistent Systems Interview Question

Difference between Mutable and non Mutable What is iBeacon Implement a queue with Array

Interview Answer

Anonymous

Jul 4, 2026

In Swift, mutability is determined by how an instance is declared (let vs. var) and whether the type is a Value Type (Structs, Enums) or a Reference Type (Classes). Value Types (Structs, Arrays, Dictionaries, etc.) Immutable (let): Once a struct instance is assigned to a constant using let, none of its properties can be modified, even if those properties were declared with var. Mutable (var): If assigned using var, its properties can be freely changed. struct Developer { var name: String } let dev1 = Developer(name: "Namita") // dev1.name = "Alex" // ❌ Compiler Error: dev1 is immutable var dev2 = Developer(name: "Namita") dev2.name = "Alex" // Valid: dev2 is mutable Reference Types (Classes) Classes behave differently. Declaring a class instance with let means you cannot point that constant to a new object instance. However, you can still mutate any of its internal properties that are declared with var. iBeacon is a protocol developed by Apple that allows mobile apps to listen for signals from physical transmitters (beacons) in the real world and react accordingly. A Queue follows the FIFO (First In, First Out) principle. struct Queue { private var array = [T?]() private var head = 0 var isEmpty: Bool { return count == 0 } var count: Int { return array.count - head } // Enqueue: Append to the end of the array - O(1) mutating func enqueue(_ element: T) { array.append(element) } // Dequeue: Remove from front efficiently using a pointer - Amortized O(1) mutating func dequeue() -> T? { guard head 50 && percentage > 0.25 { array.removeFirst(head) head = 0 } return element } // Peek at the front element without removing it func peek() -> T? { guard !isEmpty else { return nil } return array[head] } }