Mercurial > public > simoleon
comparison Simoleon/FavoritesView.swift @ 156:84137052813d
Refactor code
author | Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com> |
---|---|
date | Sat, 28 Aug 2021 11:15:25 +0100 |
parents | |
children | e4cbb1eea394 |
comparison
equal
deleted
inserted
replaced
155:681f2cbe8c7f | 156:84137052813d |
---|---|
1 //// | |
2 //// FavoritesView.swift | |
3 //// Simoleon | |
4 //// | |
5 //// Created by Dennis Concepción Martín on 19/07/2021. | |
6 //// | |
7 // | |
8 //import SwiftUI | |
9 // | |
10 //struct FavoritesView: View { | |
11 // @Environment(\.managedObjectContext) private var viewContext | |
12 // @FetchRequest( | |
13 // sortDescriptors: [NSSortDescriptor(keyPath: \Favorite.currencyPair, ascending: true)], | |
14 // animation: .default) private var favorites: FetchedResults<Favorite> | |
15 // | |
16 // var body: some View { | |
17 // VStack { | |
18 // if favorites.isEmpty { | |
19 // Group { | |
20 // Image(systemName: "star") | |
21 // .font(.title) | |
22 // | |
23 // Text("Search a currency pair and add it to favorites.") | |
24 // .padding(.top, 5) | |
25 // } | |
26 // .multilineTextAlignment(.center) | |
27 // .foregroundColor(.secondary) | |
28 // .padding(.horizontal, 50) | |
29 // } else { | |
30 // List { | |
31 // ForEach(favorites) { favorite in | |
32 // NavigationLink(destination: Conversion()) { | |
33 //// CurrencyRow(currencyPairName: favorite.currencyPair) | |
34 // } | |
35 // } | |
36 // .onDelete(perform: removeFromFavorites) | |
37 // } | |
38 // .listStyle(PlainListStyle()) | |
39 // .accessibilityIdentifier("FavoritesList") | |
40 // } | |
41 // } | |
42 // .navigationTitle("Favorites") | |
43 // .toolbar { | |
44 // #if os(iOS) | |
45 // EditButton() | |
46 // #endif | |
47 // } | |
48 // .if(UIDevice.current.userInterfaceIdiom == .phone) { content in | |
49 // NavigationView { content } | |
50 // } | |
51 // .onAppear { | |
52 // #if SCREENSHOTS | |
53 // generateFavoritesForScreenshots() | |
54 // #endif | |
55 // } | |
56 // } | |
57 // | |
58 // private func removeFromFavorites(offsets: IndexSet) { | |
59 // withAnimation { | |
60 // offsets.map { favorites[$0] }.forEach(viewContext.delete) | |
61 // | |
62 // do { | |
63 // try viewContext.save() | |
64 // } catch { | |
65 // let nsError = error as NSError | |
66 // fatalError("Unresolved error \(nsError), \(nsError.userInfo)") | |
67 // } | |
68 // } | |
69 // } | |
70 // | |
71 // #if SCREENSHOTS | |
72 // /* | |
73 // Save currencies to favourites to take screenshots for the App Store | |
74 // */ | |
75 // private func generateFavoritesForScreenshots() { | |
76 // let favoriteCurrencies = [ | |
77 // "EUR/USD", "BTC/USD", "USD/HKD", "USD/JPY", "AUD/USD", | |
78 // "XAU/GBP", "DASH/ETH", "EUR/USD", "XAG/CAD" | |
79 // ] | |
80 // | |
81 // let coreDataCurrencyPairs = favorites.map { $0.currencyPair } | |
82 // | |
83 // for favoriteCurrency in favoriteCurrencies { | |
84 // if !coreDataCurrencyPairs.contains(favoriteCurrency) { | |
85 // let favorites = Favorite(context: viewContext) | |
86 // favorites.currencyPair = favoriteCurrency | |
87 // | |
88 // do { | |
89 // try viewContext.save() | |
90 // } catch { | |
91 // let nsError = error as NSError | |
92 // fatalError("Unresolved error \(nsError), \(nsError.userInfo)") | |
93 // } | |
94 // } | |
95 // } | |
96 // } | |
97 // #endif | |
98 //} | |
99 // | |
100 //struct FavoritesView_Previews: PreviewProvider { | |
101 // static var previews: some View { | |
102 // FavoritesView() | |
103 // .environment(\.managedObjectContext, PersistenceController.preview.container.viewContext) | |
104 // } | |
105 //} |