Mercurial > public > lazybear
changeset 425:4effac4733b0
Changing keys from API responses
line wrap: on
line diff
--- a/LazyBear/ContentView.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/ContentView.swift Wed Jun 16 13:46:01 2021 +0200 @@ -67,7 +67,7 @@ let watchlistCompany = WatchlistCompany(context: moc) watchlistCompany.symbol = tupleCompany.0 watchlistCompany.name = tupleCompany.1 - watchlistCompany.watchlist = "Default watchlist" + watchlistCompany.watchlistName = "Default watchlist" } do { try moc.save()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LazyBear/Global Models/CompanyModel.swift Wed Jun 16 13:46:01 2021 +0200 @@ -0,0 +1,16 @@ +// +// CompanyModel.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 14/6/21. +// + +import SwiftUI + +struct CompanyModel: Codable, Hashable { + var symbol: String + var companyName: String + var latestPrice: Double? + var changePercent: Double? + var intradayPrices: [Double] +}
--- a/LazyBear/Global Models/CurrencyModel.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/Global Models/CurrencyModel.swift Wed Jun 16 13:46:01 2021 +0200 @@ -7,8 +7,10 @@ import SwiftUI -struct CurrencyModel: Codable { - var flag: String - var name: String - var rate: Double + +struct CurrencyModel: Codable, Hashable { + var symbol: String + var name: String + var flag: String + var rate: Double }
--- a/LazyBear/Global Models/QuoteModel.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/Global Models/QuoteModel.swift Wed Jun 16 13:46:01 2021 +0200 @@ -8,7 +8,7 @@ import SwiftUI struct QuoteModel: Codable { - var changePercent: Double? - var companyName: String - var latestPrice: Double? + var companyName: String + var latestPrice: Double? + var changePercent: Double? }
--- a/LazyBear/Global Models/TradingDatesModel.swift Sun Jun 13 19:40:42 2021 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -// -// TradingDatesModel.swift -// LazyBear -// -// Created by Dennis Concepción Martín on 21/4/21. -// - -import SwiftUI - -struct TradingDatesModel: Codable { - var date: String -}
--- a/LazyBear/Global Models/WatchlistCompany+CoreDataClass.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/Global Models/WatchlistCompany+CoreDataClass.swift Wed Jun 16 13:46:01 2021 +0200 @@ -2,7 +2,7 @@ // WatchlistCompany+CoreDataClass.swift // LazyBear // -// Created by Dennis Concepción Martín on 24/3/21. +// Created by Dennis Concepción Martín on 16/6/21. // //
--- a/LazyBear/Global Models/WatchlistCompany+CoreDataProperties.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/Global Models/WatchlistCompany+CoreDataProperties.swift Wed Jun 16 13:46:01 2021 +0200 @@ -2,7 +2,7 @@ // WatchlistCompany+CoreDataProperties.swift // LazyBear // -// Created by Dennis Concepción Martín on 24/3/21. +// Created by Dennis Concepción Martín on 16/6/21. // // @@ -16,19 +16,8 @@ return NSFetchRequest<WatchlistCompany>(entityName: "WatchlistCompany") } + @NSManaged public var name: String @NSManaged public var symbol: String - @NSManaged public var name: String - @NSManaged public var watchlist: String + @NSManaged public var watchlistName: String } - -extension WatchlistCompany : Identifiable { - -} - -extension WatchlistCompany { - static func == (lhs: WatchlistCompany, rhs: WatchlistCompany) -> Bool { - print("Custom equation has been called") - return lhs.id == rhs.id - } -}
--- a/LazyBear/Persistence.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/Persistence.swift Wed Jun 16 13:46:01 2021 +0200 @@ -22,7 +22,7 @@ let watchlistCompany = WatchlistCompany(context: viewContext) watchlistCompany.name = "Apple Inc" watchlistCompany.symbol = "AAPL" - watchlistCompany.watchlist = "Technologies" + watchlistCompany.watchlistName = "Technologies" } do { try viewContext.save()
--- a/LazyBear/Views/Company/Networking/ChartResponse.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/Views/Company/Networking/ChartResponse.swift Wed Jun 16 13:46:01 2021 +0200 @@ -12,12 +12,5 @@ var quote: [String: QuoteModel]? var latestNews: [LatestNewsModel]? var keyStats: KeyStatsModel? - - private enum CodingKeys : String, CodingKey { - case historicalPrices = "historical_prices" - case quote - case latestNews = "latest_news" - case keyStats = "key_stats" - } }
--- a/LazyBear/Views/Company/Networking/InsidersResponse.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/Views/Company/Networking/InsidersResponse.swift Wed Jun 16 13:46:01 2021 +0200 @@ -10,9 +10,4 @@ struct InsidersResponse: Codable { var insiderRoster: [InsiderRosterModel]? var insiderTransactions: [InsiderTransactionModel]? - - private enum CodingKeys: String, CodingKey { - case insiderRoster = "insider_roster" - case insiderTransactions = "insider_transactions" - } }
--- a/LazyBear/Views/Home/Helpers/CurrencyItem.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/Views/Home/Helpers/CurrencyItem.swift Wed Jun 16 13:46:01 2021 +0200 @@ -8,9 +8,7 @@ import SwiftUI struct CurrencyItem: View { - var currencySymbol: String var currency: CurrencyModel - var rectangleWidth: CGFloat? var body: some View { RoundedRectangle(cornerRadius: 8) @@ -24,7 +22,7 @@ Text(currency.flag) ) VStack(alignment: .leading) { - Text("USD/\(currencySymbol)") + Text("USD/\(currency.symbol)") .font(.headline) Text(currency.name) @@ -42,6 +40,6 @@ struct CurrencyItem_Previews: PreviewProvider { static var previews: some View { - CurrencyItem(currencySymbol: "AUD", currency: CurrencyModel(flag: "🇺🇸", name: "Australian dollar", rate: 1.3116)) + CurrencyItem(currency: CurrencyModel(symbol: "AUD", name: "Australian dollar", flag: "🇺🇸", rate: 1.3116)) } }
--- a/LazyBear/Views/Home/Helpers/CurrencyRow.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/Views/Home/Helpers/CurrencyRow.swift Wed Jun 16 13:46:01 2021 +0200 @@ -8,7 +8,7 @@ import SwiftUI struct CurrencyRow: View { - var latestCurrencies: [String: CurrencyModel] + var latestCurrencies: [CurrencyModel] @State private var showExtensiveList = false @@ -35,8 +35,8 @@ ScrollView(.horizontal, showsIndicators: false) { HStack(spacing: 20) { - ForEach(Array(latestCurrencies.keys), id: \.self) { currencySymbol in - CurrencyItem(currencySymbol: currencySymbol, currency: latestCurrencies[currencySymbol]!) + ForEach(latestCurrencies, id: \.self) { currency in + CurrencyItem(currency: currency) } } .padding() @@ -50,6 +50,6 @@ struct CurrencyRow_Previews: PreviewProvider { static var previews: some View { - CurrencyRow(latestCurrencies: ["AUD": CurrencyModel(flag: "🇺🇸", name: "Australian dollar", rate: 1.3116)]) + CurrencyRow(latestCurrencies: [CurrencyModel(symbol: "AUD", name: "Australian dollar", flag: "🇺🇸", rate: 1.3116)]) } }
--- a/LazyBear/Views/Home/Helpers/CurrencySheet.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/Views/Home/Helpers/CurrencySheet.swift Wed Jun 16 13:46:01 2021 +0200 @@ -8,14 +8,14 @@ import SwiftUI struct CurrencySheet: View { + var latestCurrencies: [CurrencyModel] @Environment(\.presentationMode) private var currencySheetPresentation - var latestCurrencies: [String: CurrencyModel] var body: some View { NavigationView { VStack { - List(Array(latestCurrencies.keys.sorted()), id: \.self) { currencySymbol in - CurrencySheetRow(currencySymbol: currencySymbol, currency: latestCurrencies[currencySymbol]!) + List(latestCurrencies, id: \.self) { currency in + CurrencySheetRow(currency: currency) } } .navigationTitle("Currencies") @@ -33,6 +33,6 @@ struct CurrencySheet_Previews: PreviewProvider { static var previews: some View { - CurrencySheet(latestCurrencies: ["AUD": CurrencyModel(flag: "🇦🇺", name: "Australian dollar", rate: 1.2938)]) + CurrencySheet(latestCurrencies: [CurrencyModel(symbol: "AUD", name: "Australian dollar", flag: "🇦🇺", rate: 1.2938)]) } }
--- a/LazyBear/Views/Home/Helpers/CurrencySheetRow.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/Views/Home/Helpers/CurrencySheetRow.swift Wed Jun 16 13:46:01 2021 +0200 @@ -8,7 +8,6 @@ import SwiftUI struct CurrencySheetRow: View { - var currencySymbol: String var currency: CurrencyModel var body: some View { @@ -17,7 +16,7 @@ .padding(.trailing) VStack(alignment: .leading) { - Text("USD/\(currencySymbol)") + Text("USD/\(currency.symbol)") .font(.headline) Text(currency.name) @@ -34,6 +33,6 @@ struct CurrencySheetRow_Previews: PreviewProvider { static var previews: some View { - CurrencySheetRow(currencySymbol: "AUD", currency: CurrencyModel(flag: "🇦🇺", name: "Australian dollar", rate: 1.2938)) + CurrencySheetRow(currency: CurrencyModel(symbol: "AUD", name: "Australian dollar", flag: "🇦🇺", rate: 1.2938)) } }
--- a/LazyBear/Views/Home/Helpers/StockItem.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/Views/Home/Helpers/StockItem.swift Wed Jun 16 13:46:01 2021 +0200 @@ -9,9 +9,7 @@ import StockCharts struct StockItem: View { - var symbol: String - var company: QuoteModel - var intradayPrices: [Double]? + var company: CompanyModel var body: some View { RoundedRectangle(cornerRadius: 20) @@ -21,7 +19,7 @@ .overlay( VStack(alignment: .leading) { Group { - Text(symbol.uppercased()) + Text(company.symbol.uppercased()) .fontWeight(.semibold) .padding(.top) @@ -49,12 +47,9 @@ Spacer() - if let prices = intradayPrices { - LineChartView(data: prices, dates: nil, hours: nil, dragGesture: false) - .padding(.vertical) - .clipShape(RoundedRectangle(cornerRadius: 20)) - } - + LineChartView(data: company.intradayPrices, dates: nil, hours: nil, dragGesture: false) + .padding(.vertical) + .clipShape(RoundedRectangle(cornerRadius: 20)) } ,alignment: .leading ) @@ -63,9 +58,6 @@ struct StockItem_Previews: PreviewProvider { static var previews: some View { - StockItem( - symbol: "aapl", - company: QuoteModel(changePercent: 0.03, companyName: "Apple Inc", latestPrice: 120.3) - ) + StockItem(company: CompanyModel(symbol: "aapl", companyName: "Apple Inc", latestPrice: 120.3, changePercent: 0.03, intradayPrices: [120.3])) } }
--- a/LazyBear/Views/Home/Helpers/StockRow.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/Views/Home/Helpers/StockRow.swift Wed Jun 16 13:46:01 2021 +0200 @@ -9,13 +9,14 @@ struct StockRow: View { - var list: [String: [String: QuoteModel]] - var intradayPrices: [String: [Double]]? + var listName: String + var companies: [CompanyModel] + var showWatchlistSheet: Bool? @State private var showList = false + @Environment(\.managedObjectContext) private var moc var body: some View { - let listName = list.first!.key VStack(alignment: .leading) { HStack(alignment: .bottom) { VStack(alignment: .leading) { @@ -38,9 +39,8 @@ ScrollView(.horizontal, showsIndicators: false) { HStack(spacing: 20) { - let companies = list[listName] - ForEach(Array(companies!.keys), id: \.self) { symbol in - StockItem(symbol: symbol, company: companies![symbol]!, intradayPrices: intradayPrices![symbol]) + ForEach(companies, id: \.self) { company in + StockItem(company: company) } } .padding() @@ -49,7 +49,12 @@ } .padding(.bottom) .sheet(isPresented: $showList) { - StockSheet(listName: adaptListTitle(listName), companies: list[list.first!.key]!, intradayPrices: intradayPrices) + if showWatchlistSheet ?? false { + WatchlistSheet(listName: adaptListTitle(listName), companies: companies) + .environment(\.managedObjectContext, self.moc) + } else { + StockSheet(listName: adaptListTitle(listName), companies: companies) + } } } @@ -69,8 +74,8 @@ struct StockRectangleRow_Previews: PreviewProvider { static var previews: some View { StockRow( - list: ["mostactive": ["AAPL": QuoteModel(changePercent: 0.03, companyName: "Apple Inc", latestPrice: 130.3)]], - intradayPrices: ["AAPL": [130.2]] + listName: "mostactive", + companies: [CompanyModel(symbol: "aapl", companyName: "Apple Inc", latestPrice: 120.3, changePercent: 0.03, intradayPrices: [120.3])] ) } }
--- a/LazyBear/Views/Home/Helpers/StockSheet.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/Views/Home/Helpers/StockSheet.swift Wed Jun 16 13:46:01 2021 +0200 @@ -9,18 +9,15 @@ struct StockSheet: View { var listName: String - var companies: [String: QuoteModel] - var intradayPrices: [String: [Double]]? + var companies: [CompanyModel] @Environment(\.presentationMode) private var stockSheetPresentation var body: some View { NavigationView { VStack { - List(Array(companies.keys.sorted()), id: \.self) { symbol in - NavigationLink(destination: CompanyView(symbol: symbol)) { - StockSheetRow(symbol: symbol, company: companies[symbol]!, intradayPrices: intradayPrices![symbol]!) - } + List(companies, id: \.self) { company in + StockSheetRow(company: company) } } .navigationTitle(listName) @@ -38,6 +35,9 @@ struct StockSheet_Previews: PreviewProvider { static var previews: some View { - StockSheet(listName: "Most active", companies: ["aapl": QuoteModel(changePercent: 0.03, companyName: "Apple Inc", latestPrice: 120.3)]) + StockSheet( + listName: "Most active", + companies: [CompanyModel(symbol: "aapl", companyName: "Apple Inc", latestPrice: 120.3, changePercent: 0.03, intradayPrices: [120.3])] + ) } }
--- a/LazyBear/Views/Home/Helpers/StockSheetRow.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/Views/Home/Helpers/StockSheetRow.swift Wed Jun 16 13:46:01 2021 +0200 @@ -9,14 +9,12 @@ import StockCharts struct StockSheetRow: View { - var symbol: String - var company: QuoteModel - var intradayPrices: [Double]? + var company: CompanyModel var body: some View { HStack { VStack(alignment: .leading) { - Text(symbol.capitalized.capitalized) + Text(company.symbol.uppercased()) .fontWeight(.semibold) Text(company.companyName.capitalized) @@ -27,12 +25,11 @@ } Spacer() - if let prices = intradayPrices { - LineChartView(data: prices, dates: nil, hours: nil, dragGesture: false) - .frame(width: 80) - .padding(.vertical, 10) - .padding(.leading) - } + LineChartView(data: company.intradayPrices, dates: nil, hours: nil, dragGesture: false) + .frame(width: 80) + .padding(.vertical, 10) + .padding(.horizontal) + if let latestPrice = company.latestPrice, let changePercent = company.changePercent { VStack(alignment: .trailing) { @@ -52,9 +49,6 @@ struct StockSheetRow_Previews: PreviewProvider { static var previews: some View { - StockSheetRow( - symbol: "aapl", - company: QuoteModel(changePercent: 0.03, companyName: "Apple Inc", latestPrice: 120.3) - ) + StockSheetRow(company: CompanyModel(symbol: "aapl", companyName: "Apple Inc", latestPrice: 120.3, changePercent: 0.03, intradayPrices: [120.3])) } }
--- a/LazyBear/Views/Home/HomeView.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/Views/Home/HomeView.swift Wed Jun 16 13:46:01 2021 +0200 @@ -31,14 +31,13 @@ } if let lists = home.data.lists { - let mirror = Mirror(reflecting: lists) - ForEach(Array(mirror.children), id: \.label) { child in - if let list = child.value as? [String : QuoteModel] { - StockRow(list: [child.label!: list], intradayPrices: home.data.intradayPrices) - .listRowInsets(EdgeInsets()) - } + let listNames = Array(lists.keys.sorted()) + ForEach(listNames, id: \.self) { listName in + StockRow(listName: listName, companies: lists[listName]!) + .listRowInsets(EdgeInsets()) } } + if let latestCurrencies = home.data.latestCurrencies { CurrencyRow(latestCurrencies: latestCurrencies) .listRowInsets(EdgeInsets())
--- a/LazyBear/Views/Home/Networking/HomeResponse.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/Views/Home/Networking/HomeResponse.swift Wed Jun 16 13:46:01 2021 +0200 @@ -8,24 +8,8 @@ import SwiftUI struct HomeResponse: Codable { - var intradayPrices: [String: [Double]]? - var latestCurrencies: [String: CurrencyModel]? - var lists: ListsModel? - var sectorPerformance: [SectorPerformanceModel]? - var tradingDates: [TradingDatesModel]? - - private enum CodingKeys : String, CodingKey { - case intradayPrices = "intraday_prices" - case latestCurrencies = "latest_currencies" - case lists - case sectorPerformance = "sector_performance" - case tradingDates = "trading_dates" - } + var latestCurrencies: [CurrencyModel]? + var lists: [String: [CompanyModel]]? /// String = list name + var sectorPerformance: [SectorPerformanceModel]? + var tradingDates: [String]? } - - -struct ListsModel: Codable { - var mostactive: [String: QuoteModel]? - var gainers: [String: QuoteModel]? - var losers: [String: QuoteModel]? -}
--- a/LazyBear/Views/Home/TradingDates.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/Views/Home/TradingDates.swift Wed Jun 16 13:46:01 2021 +0200 @@ -9,7 +9,7 @@ struct TradingDates: View { - var dates: [TradingDatesModel] + var dates: [String] @Environment(\.presentationMode) private var presentationTradingDates let columns = [GridItem(.adaptive(minimum: 100))] @@ -18,8 +18,8 @@ NavigationView { ScrollView { LazyVGrid(columns: columns, spacing: 20) { - ForEach(getArrayOfDates(), id: \.self) { date in - TradingDatesItem(date: date) + ForEach(dates, id: \.self) { date in + TradingDatesItem(date: convertStringToDate(date)) } } .padding() @@ -36,31 +36,11 @@ } } } - - /* - Get array of dates to use in ForEach - */ - private func getArrayOfDates() -> [Date] { - // Get array of the string dates - let stringDates = self.dates.map { $0.date } - - // Convert string to date - let dateFormatter = DateFormatter() - dateFormatter.dateFormat = "yyyy-MM-dd" - - // Append dates to a Date array - var dates = [Date]() - for stringDate in stringDates { - dates.append(dateFormatter.date(from: stringDate)!) - } - - return dates - } } struct TradingDate_Previews: PreviewProvider { static var previews: some View { // Format is YYYY-MM-DD - TradingDates(dates: [TradingDatesModel(date: "2021-01-01")]) + TradingDates(dates: ["2021-01-01"]) } }
--- a/LazyBear/Views/Profile/Helpers/TextfieldAlert.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/Views/Profile/Helpers/TextfieldAlert.swift Wed Jun 16 13:46:01 2021 +0200 @@ -8,7 +8,7 @@ import SwiftUI struct TextfieldAlert: View { - var listName: String + var watchlistName: String @State private var newListName: String = String() @Binding var showRenameAction: Bool @@ -16,7 +16,7 @@ @Environment(\.managedObjectContext) private var moc @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: []) - var watchlistCompany: FetchedResults<WatchlistCompany> + var watchlistCompanies: FetchedResults<WatchlistCompany> var body: some View { RoundedRectangle(cornerRadius: 15) @@ -77,10 +77,10 @@ /* Rename watchlist name in Core Data */ - private func renameList(_ newListName: String) { - let selectedWatchlist = watchlistCompany.filter({ $0.watchlist == listName }) + private func renameList(_ newWatchlistName: String) { + let selectedWatchlist = watchlistCompanies.filter({ $0.watchlistName == watchlistName }) for company in selectedWatchlist { - company.watchlist = newListName + company.watchlistName = newWatchlistName } do { try moc.save() @@ -103,6 +103,6 @@ @Environment(\.presentationMode) static var presentationMode static var previews: some View { - TextfieldAlert(listName: "MyWatchlist", showRenameAction: .constant(true), presentationMode: presentationMode) + TextfieldAlert(watchlistName: "MyWatchlist", showRenameAction: .constant(true), presentationMode: presentationMode) } }
--- a/LazyBear/Views/Profile/Helpers/WatchlistCreator.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/Views/Profile/Helpers/WatchlistCreator.swift Wed Jun 16 13:46:01 2021 +0200 @@ -99,7 +99,7 @@ let watchlistCompany = WatchlistCompany(context: moc) watchlistCompany.name = company.securityName ?? "-" watchlistCompany.symbol = company.symbol! - watchlistCompany.watchlist = watchlistCreatorClass.name + watchlistCompany.watchlistName = watchlistCreatorClass.name } do {
--- a/LazyBear/Views/Profile/Networking/Profile.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/Views/Profile/Networking/Profile.swift Wed Jun 16 13:46:01 2021 +0200 @@ -19,7 +19,7 @@ case .initial: self.data = response default: - self.data.quotes = response.quotes + self.data = response } self.showView = true
--- a/LazyBear/Views/Profile/Networking/ProfileResponse.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/Views/Profile/Networking/ProfileResponse.swift Wed Jun 16 13:46:01 2021 +0200 @@ -8,11 +8,5 @@ import SwiftUI struct ProfileResponse: Codable { - var intradayPrices: [String: [Double]]? - var quotes: [String: QuoteModel]? - - private enum CodingKeys : String, CodingKey { - case intradayPrices = "intraday_prices" - case quotes - } + var quotes: [CompanyModel]? }
--- a/LazyBear/Views/Search/Helpers/SearchedCompanyItem.swift Sun Jun 13 19:40:42 2021 +0200 +++ b/LazyBear/Views/Search/Helpers/SearchedCompanyItem.swift Wed Jun 16 13:46:01 2021 +0200 @@ -12,14 +12,14 @@ @Environment(\.managedObjectContext) private var moc @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: []) - var watchlistCompany: FetchedResults<WatchlistCompany> + var watchlistCompanies: FetchedResults<WatchlistCompany> @State private var showingWatchlistSelector = false var body: some View { HStack { Button(action: { self.showingWatchlistSelector = true }) { - let watchlistSymbols = watchlistCompany.map { $0.symbol } + let watchlistSymbols = watchlistCompanies.map { $0.symbol } if watchlistSymbols.contains(company.symbol!) { Image(systemName: "star.fill") .foregroundColor(.yellow) @@ -60,7 +60,7 @@ */ private func generateButtons() -> [ActionSheet.Button] { var actionButtons = [ActionSheet.Button]() - let watchlists = Set(watchlistCompany.map { $0.watchlist }) + let watchlists = Set(watchlistCompanies.map { $0.watchlistName }) for watchlistName in watchlists { actionButtons.append( @@ -78,11 +78,11 @@ /* When the user taps the watchlist -> save the company to CoreData */ - private func addCompany(_ symbol: String, _ name: String, _ watchlist: String) { + private func addCompany(_ symbol: String, _ name: String, _ watchlistName: String) { let watchlistCompany = WatchlistCompany(context: moc) watchlistCompany.symbol = symbol watchlistCompany.name = name - watchlistCompany.watchlist = watchlist + watchlistCompany.watchlistName = watchlistName do { try moc.save() print("Company saved")