Skip to content

Instantly share code, notes, and snippets.

@fitomad
Created May 5, 2020 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fitomad/a5f4bc0b71b0fe1e3da9ceb5d605f8e5 to your computer and use it in GitHub Desktop.
Save fitomad/a5f4bc0b71b0fe1e3da9ceb5d605f8e5 to your computer and use it in GitHub Desktop.
@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