Skip to content
Justice Tech School

assert and precondition

assert checks during development only. precondition checks in release builds too.

Example
func half(_ n: Int) -> Int {
    precondition(n % 2 == 0, "n must be even")
    return n / 2
}
print(half(8))
assert(half(4) == 2)

Exercise

Always checked.

(cond, "msg")

Quiz Test

Which is stripped in release?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.