deda9 / Require

Defensive programming sugar syntax

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Require

Based on Defensive programming, we should valid all the inputs, so this's sugar syntax to valid the input, so this crash in only in debug build if the condition is false

var month: Int = 20

require(1...12 ~= month) {
    "Month: \(month) should be within 1...12"
}

Output: Assertion failed: Debug crash: Month: 20 should be within 1...12 in file: MyPlayground.playground, line: 4

About

Defensive programming sugar syntax


Languages

Language:Swift 100.0%