Skip to content

Instantly share code, notes, and snippets.

@fitomad
Created May 5, 2020 16:41
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/a907c7d4dd42f3d5da7beaf08f246440 to your computer and use it in GitHub Desktop.
Save fitomad/a907c7d4dd42f3d5da7beaf08f246440 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
/// Esto es lo que queremos *mostrar*
public var projectedValue: Power
{
return self
}
/// 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