Skip to content

Instantly share code, notes, and snippets.

@fitomad

fitomad/wrapper_tercero.swift Secret

Created May 5, 2020
Embed
What would you like to do?
@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
You can’t perform that action at this time.