diff Simoleon/Settings.swift @ 75:b6f8661300f2

Added isLocked to CurrencyPairs
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Fri, 30 Jul 2021 15:52:27 +0100
parents 2b85d6ed433e
children 822175ac4343
line wrap: on
line diff
--- a/Simoleon/Settings.swift	Thu Jul 29 17:01:15 2021 +0100
+++ b/Simoleon/Settings.swift	Fri Jul 30 15:52:27 2021 +0100
@@ -20,7 +20,21 @@
     @State private var showingAlert = false
     @State private var searchCurrency = ""
     
-    let currencyPairs: [String] = parseJson("CurrencyPairs.json")
+    let currencyPairs: [CurrencyPairModel] = parseJson("CurrencyPairs.json")
+    
+    /*
+     If searched currency string is empty:
+     * Show all currencies
+     else:
+     * Show filtered list of currencies containing searched currency string
+     */
+    var searchResults: [CurrencyPairModel] {
+        if searchCurrency.isEmpty {
+            return currencyPairs.sorted { $0.name < $1.name }
+        } else {
+            return currencyPairs.filter { $0.name.contains(searchCurrency.uppercased()) }
+        }
+    }
     
     var body: some View {
         List {
@@ -31,7 +45,7 @@
                             .padding(5)
                         
                         ForEach(searchResults, id: \.self) { currencyPair in
-                            Text(currencyPair)
+                            Text(currencyPair.name)
                         }
                     }
                 } else {
@@ -115,21 +129,6 @@
             NavigationView { content }
         }
     }
-    
-    /*
-     If searched currency string is empty:
-     * Show all currencies
-     else:
-     * Show filtered list of currencies containing searched currency string
-     */
-    var searchResults: [String] {
-        if searchCurrency.isEmpty {
-            return currencyPairs.sorted()
-        } else {
-            return currencyPairs.filter { $0.contains(searchCurrency.uppercased()) }
-        }
-    }
-    
      
     // Save default currency to core data
     private func setCoreData() {