April 2026
Intermediate
683 pages
25h 29m
English
Yeah, you heard right: Swift allows you to nest child functions into parent functions, not unlike a dream within a dream as in the Inception movie. In case you missed the movie, Listing 5.49 features a simple example in which the parent isNameValid function contains nested child functions isLongEnough, hasNoSpaces, and hasNoNumbers.
// Functionfunc isNameValid(_ name: String) -> Bool { func isLongEnough(_ name: String) -> Bool { return name.count >= 3 } func hasNoSpaces(_ name: String) -> Bool { return !name.contains(" ") } func hasNoNumbers(_ name: String) -> Bool { return !name.contains { $0.isNumber } } return isLongEnough(name) && hasNoSpaces(name) && hasNoNumbers(name)}// Main flowisNameValid("John") // true
Read now
Unlock full access