Do you write the code like this in SWIFT? π
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
class AccountItem { var companyName: String let name: String let number: String let balance: String? init(_ companyName: String, _ name: String, _ number: String, _ balance: String?, showCompanyName: Bool?) { if(showCompanyName == true){ self.companyName = companyName } else { self.companyName = "" } self.name = name self.number = number self.balance = balance } } |
Number Formatting in SWIFT π
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
func onlyCashLessEUR(_ rates : [CurrencyRateMto]) -> CurrencyRateItem { var EUR : CurrencyRateItem? = nil let cashLessEUR = rates.filter({$0.type.enumValue == CurrencyRateTypeMtoEnum.CASHLESS && $0.currency.isEUR() == true}) if(cashLessEUR.count > 0){ EUR = CurrencyRateItem( cashLessEUR.first?.currency.getIcon(), (cashLessEUR.first?.currency.id)!, NumberFormatting.sum(cashLessEUR.first?.buyPrice?.price), NumberFormatting.sum(cashLessEUR.first?.sellPrice?.price)) } if(EUR == nil){ EUR = CurrencyRateItem( UIImage.init(named: "currency_eur"), "EUR", "-", "-") } return EUR! } |