Skip to content

Instantly share code, notes, and snippets.

@karthikgs7
Created November 27, 2019 13:02
Show Gist options
  • Save karthikgs7/87e510ae6b1cb56dcd32008f13891632 to your computer and use it in GitHub Desktop.
Save karthikgs7/87e510ae6b1cb56dcd32008f13891632 to your computer and use it in GitHub Desktop.
@propertyWrapper
struct UpperCased {
private(set) var value: String = ""
init(wrappedValue initialValue: String) {
self.wrappedValue = initialValue
}
var wrappedValue: String {
get { value }
set { value = newValue.uppercased() }
}
}
@propertyWrapper
struct Currency {
private let currencyCode: String
private(set) var value: String = ""
init(wrappedValue initialValue: String, currencyCode: String) {
self.currencyCode = currencyCode.uppercased()
self.wrappedValue = self.currencyCode + " " + initialValue
}
var wrappedValue: String {
get { value }
set { value = newValue }
}
}
/*
struct CurrencyTest {
@Currency(currencyCode: "SGD") var totalAmount = "2.0"
@Currency(currencyCode: "INR") var inrAmount = "100.0"
}
let currencyTest = CurrencyTest(totalAmount: "5.0")
print(currencyTest.totalAmount)
print(currencyTest.inrAmount)
let range = 0.0..<5.0
if range.contains(0.3) {
print("inside range...")
} else {
print("outside range...")
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment