Created
November 27, 2019 13:02
-
-
Save karthikgs7/87e510ae6b1cb56dcd32008f13891632 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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