iOS ● ○ ○ Swift 6

Kodebits Day 50: Class Reference Share

Jul 1 2026
Practice classes with a short swift challenge.

What is the output?

class Box {
  var value: Int
  init(_ v: Int) { value = v }
}
let a = Box(5)
let b = a
b.value = 12
print(a.value)
print(b.value)


Try it in the online Swift Playground →

[spoiler title="Solution"]

Answer:

12
12

Explanation:

Classes are reference types, so a and b share the same instance.

[/spoiler]


Further Reading