Imutation

Creating imutate/mutate functions using Extension in swift :

 

extension Int {

    func double() -> Int {

        return 2 * self

    }

  

    mutating func doubleMe() {

        self = 2 * self

    }

}

 © Xosrov 2016