Post

Replies

Boosts

Views

Activity

Reply to SwiftUI and Measurement
@countermind works really well, and I will add a bit more especially for the newer SwiftUI user like myself. I created a MyButton and having the distance as an @ObservedObject for reactivity. class MyDistance: ObservableObject { @Published var distance: Measurement<UnitLength> init() { distance = Measurement<UnitLength>(value: 13.37, unit: .meters) } } struct ContentView: View { @StateObject var distance = MyDistance() var body: some View { VStack { Text("\(distance.distance.formatted(.measurement(width: .abbreviated, usage: .asProvided, numberFormatStyle: .number)))") MyButton(distance: distance) } .frame(minWidth: 300) .padding() } } struct MyButton: View { // for reactivity. @ObservedObject var distance: MyDistance var body: some View { Button("Convert to km") { print("Convert to km"); distance.distance = distance.distance.converted(to: .kilometers) } } }
Topic: App & System Services SubTopic: General Tags:
Feb ’25
Reply to Is there an official list of currencies supported by in-app purchase?
Hi there, I was searching for the answer and bumped into this just an update since locale.currencyCode is decprecated. locale.currencyCode is replaced with Locale( identifier: identifier ).currency but it can be nil so I use if let. I am still a beginner in Swift, please let me know if there is anyting wrong with the code. func generateCurrencyCode (){ var currencyCode = Set<String>() for identifier in Locale.availableIdentifiers { if let locale = Locale( identifier: identifier ).currency { currencyCode.insert(locale.identifier) // locale returns Currency(_identifier: ____, _normalizedIdentifier: _____ ) } } return currencyCode } currencyCode will be as follow ["ZMW", "TJS", "COP", "JMD", "CRC", "GMD", "AFN", "FKP", "NAD", "MAD", "AMD", "IRR", "BIF", "QAR", "MXN", "MKD", "MZN", "BRL", "CVE", "BWP", "ETB", "HUF", "SLL", "XCD", "THB", "ALL", "BDT", "XPF", "BBD", "BOB", "BGN", "TZS", "BHD", "MGA", "SHP", "KMF", "KZT", "PAB", "SGD", "AZN", "BMD", "BAM", "KHR", "TOP", "RWF", "AOA", "GNF", "TWD", "HNL", "PKR", "JPY", "PGK", "CDF", "SEK", "TTD", "MRU", "SSP", "PYG", "USD", "MNT", "MMK", "VUV", "BSD", "HKD", "EGP", "LYD", "NGN", "MOP", "ILS", "UGX", "BTN", "UAH", "RON", "LKR", "MDL", "KRW", "NPR", "ANG", "DZD", "RUB", "NZD", "KES", "EUR", "CZK", "XOF", "HTG", "KGS", "SRD", "TND", "KPW", "GHS", "SDG", "NOK", "GEL", "MYR", "LAK", "MUR", "XAF", "IQD", "PHP", "STN", "ARS", "SOS", "INR", "TRY", "GIP", "JOD", "DKK", "SCR", "CAD", "DOP", "KYD", "OMR", "KWD", "CNY", "GBP", "SBD", "GYD", "BZD", "CLP", "NIO", "FJD", "SAR", "DJF", "PEN", "MVR", "SZL", "MWK", "ZAR", "BND", "UYU", "AED", "RSD", "LRD", "AUD", "GTQ", "IDR", "SYP", "LBP", "AWG", "CHF", "YER", "UZS", "ISK", "BYN", "PLN", "CUP", "ERN", "VES", "TMT", "VND", "WST"]
Topic: App & System Services SubTopic: StoreKit Tags:
Mar ’23