-
-
Save fitomad/a5f4bc0b71b0fe1e3da9ceb5d605f8e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@propertyWrapper | |
public struct Power | |
{ | |
/// Número que queremos elevar | |
public private(set) var value: Int | |
/// Potencia a la que vamos a elevar el número | |
public private(set) var power: Int | |
/// Obligatorio | |
public var wrappedValue: Int | |
{ | |
get | |
{ | |
Int(pow(Double(self.value), Double(self.power))) | |
} | |
set | |
{ | |
self.value = newValue | |
} | |
} | |
/** | |
Inicializamos el *wrapper* sabiendo | |
sólo la potencia. | |
*/ | |
public init(_ power: Int) | |
{ | |
self.power = power | |
self.value = 0 | |
} | |
/** | |
Ya sabemos el número y la potencia | |
a la que queremos elevarlo. | |
*/ | |
public init(wrappedValue: Int, _ power: Int) | |
{ | |
self.power = power | |
self.value = wrappedValue | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment