Swift 5.1: Extensions Cheat Sheet

// Extensions add new functionality to an existing
// class, structure, enumeration, or protocol type
extension String {

  // Extending String type to calculate
  // if a String instance is truthy or falsy
  var boolValue: Bool {
    if self == "1" {
      return true
    }
    return false
  }
}

let isTrue = "0".boolValue

Leave a Reply

Your email address will not be published. Required fields are marked *