 
 
 // Subscripts
+// This example adds an integer subscript to Swift’s built-in Int type. This subscript [n] returns the decimal digit n places in from the right of the number:
 extension Int {
     subscript(digitIndex: Int) -> Int {
         var decimalBase = 1


// Methods
extension Int {
    func repetitions(task: () -> ()) {
        for _ in 0..<self {
            task()
        }
    }
}

3.repetitions({ print("Hello!") })
3.repetitions { print("Goodbye!") }


// Mutating Instance Methods

746381295[1]
746381295[2]
746381295[8]

// If the Int value does not have enough digits for the requested index, the subscript implementation returns 0, as if the number had been padded with zeros to the left:

746381295[9]


// Nested Types
extension Int {
    enum Kind {
        case negative, zero, positive
    }
    
    var kind: Kind {
        switch self {
        case 0:
            return .zero
        case let x where x > 0:
            return .positive
        default:
            return .negative
        }
    }
}


func printIntegerKinds(_ numbers: [Int]) {
    for number in numbers {
        switch number.kind {
        case .negative:
            print("-")
            //print("- ", terminator: false)
        case .zero:
            print("0")
            //print("0 ", terminator: false)
        case .positive:
            print("+")
            //print("+ ", terminator: false)
        }
