Exercise 2: ShoppingCart Class Showing Shared Reference Semantics — Possible Solution ============================================================================================ class ShoppingCart { var itemCount = 0 func addItem() { itemCount += 1 } } let cartA = ShoppingCart() let cartB = cartA cartB.addItem() print(cartA.itemCount) // Prints: 1 print(cartB.itemCount) // Prints: 1 HOW IT WORKS: ShoppingCart is a class, so `let cartB = cartA` does NOT create a separate instance - cartB simply becomes a second reference pointing at the exact same underlying ShoppingCart object that cartA already refers to. There is only ever one real ShoppingCart instance in memory here, with two names (cartA and cartB) both referring to it. Calling cartB.addItem() mutates that single shared instance's own itemCount property directly. Because cartA refers to that identical instance, reading cartA.itemCount afterward reflects the exact same change - both print 1, since there was never a second, independent cart to begin with. Note that cartA and cartB are both declared with let, which is still valid here: let only prevents cartA/cartB themselves from later being reassigned to point at a DIFFERENT instance - it says nothing about whether the instance they point at can have its own properties mutated, which addItem() is free to do since itemCount is declared var inside the class. ANSWER: Both cartA.itemCount and cartB.itemCount print 1 after calling addItem() through cartB, because assigning a class instance (let cartB = cartA) shares the same underlying reference rather than copying it - there was only ever one real ShoppingCart object, so a change made through either name is visible through both. WHY THIS WORKS AS AN ANSWER ------------------------------ This correctly demonstrates that assigning a class instance shares a single underlying reference, verified with printed real values showing a mutation made through one variable name visible through the other.