iOS ● ○ ○ Swift 6

Kodebits Day 66: Designated Initializer

Jul 28 2026
Practice initialization with a short swift challenge.

What does this print?

struct User {
  var name: String
  var age: Int
  init(name: String) {
    self.name = name
    self.age = 0
  }
}
let u = User(name: "Alice")
print(u.name)
print(u.age)


Try it in the online Swift Playground →

[spoiler title="Solution"]

Answer:

Alice
0

Explanation:

Custom initializers set all properties, providing defaults as needed.

[/spoiler]


Further Reading