Skip to content

Instantly share code, notes, and snippets.

@fitomad
Created May 5, 2020 11:46
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/0131b8363fa8b5bd4abded805861fccf to your computer and use it in GitHub Desktop.
Save fitomad/0131b8363fa8b5bd4abded805861fccf to your computer and use it in GitHub Desktop.
@propertyWrapper
public struct Power
{
/// Número que queremos elevar
private var value: Int
/// Potencia a la que vamos a elevar el número
private 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