Mercurial > public > lazybear
changeset 82:0730f031e478
New CoreData is working
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Mon, 25 Jan 2021 12:53:30 +0100 |
parents | 12a0776e6d9a |
children | fce6e0364c1c |
files | LazyBear.xcodeproj/project.pbxproj LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate lazybear/ContentView.swift lazybear/Core Data/Persistence.swift lazybear/Functions/Model.swift lazybear/Functions/RandomColor.swift lazybear/LazyBearApp.swift lazybear/Supply views/AddWatchlist.swift lazybear/Supply views/Company.swift lazybear/Supply views/CompanyList.swift lazybear/Supply views/CompanyRow.swift lazybear/Supply views/CurrentPrice.swift lazybear/Supply views/HeaderWatchList.swift lazybear/Supply views/Row.swift lazybear/Supply views/Stock.swift lazybear/Supply views/Watchlist.swift |
diffstat | 16 files changed, 149 insertions(+), 267 deletions(-) [+] |
line wrap: on
line diff
--- a/LazyBear.xcodeproj/project.pbxproj Mon Jan 25 12:07:09 2021 +0100 +++ b/LazyBear.xcodeproj/project.pbxproj Mon Jan 25 12:53:30 2021 +0100 @@ -9,7 +9,6 @@ /* Begin PBXBuildFile section */ 95002580256D17D9008FFD28 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9500257F256D17D9008FFD28 /* StoreKit.framework */; }; 950B79F625B1CB7A00E5DB5B /* CompanyList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950B79F525B1CB7A00E5DB5B /* CompanyList.swift */; }; - 952498B325BB381300B00E22 /* CurrentPrice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 952498B225BB381300B00E22 /* CurrentPrice.swift */; }; 952498B625BB47A700B00E22 /* LatestPriceModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 952498B525BB47A700B00E22 /* LatestPriceModel.swift */; }; 9537923625BDF85D0001F82B /* GoogleApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9537923525BDF85D0001F82B /* GoogleApi.swift */; }; 9537924A25BDFCD70001F82B /* LoadImageTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9537924925BDFCD70001F82B /* LoadImageTest.swift */; }; @@ -20,7 +19,7 @@ 95700BC625BD9D12009CEEFE /* IexApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95700BC525BD9D12009CEEFE /* IexApi.swift */; }; 95AB4A7A259DCBAE0064C9C1 /* ReadJson.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95AB4A79259DCBAE0064C9C1 /* ReadJson.swift */; }; 95AB4A7D259DCC0C0064C9C1 /* CompanyModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95AB4A7C259DCC0C0064C9C1 /* CompanyModel.swift */; }; - 95AB4A90259DD66D0064C9C1 /* CompanyRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95AB4A8F259DD66D0064C9C1 /* CompanyRow.swift */; }; + 95AB4A90259DD66D0064C9C1 /* Row.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95AB4A8F259DD66D0064C9C1 /* Row.swift */; }; 95B04EB325212369000AD27F /* LazyBearApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B04EB225212369000AD27F /* LazyBearApp.swift */; }; 95B04EB525212369000AD27F /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95B04EB425212369000AD27F /* ContentView.swift */; }; 95B04EB72521236A000AD27F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 95B04EB62521236A000AD27F /* Assets.xcassets */; }; @@ -32,17 +31,14 @@ 95E4118F25BEC35D00A9C23F /* SDWebImageSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 95E4118E25BEC35D00A9C23F /* SDWebImageSwiftUI */; }; 95E4119225BEC56F00A9C23F /* Header.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E4119125BEC56F00A9C23F /* Header.swift */; }; 95E4119625BEC9DD00A9C23F /* TestViewBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E4119525BEC9DD00A9C23F /* TestViewBuilder.swift */; }; - 95E4119A25BECCB200A9C23F /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E4119925BECCB200A9C23F /* Model.swift */; }; 95E411A225BEDDC400A9C23F /* WatchlistCompany+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E411A025BEDDC400A9C23F /* WatchlistCompany+CoreDataClass.swift */; }; 95E411A325BEDDC400A9C23F /* WatchlistCompany+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E411A125BEDDC400A9C23F /* WatchlistCompany+CoreDataProperties.swift */; }; - 95F6C2E425BAD529003CF389 /* RandomColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F6C2E325BAD529003CF389 /* RandomColor.swift */; }; + 95E411A725BEE03000A9C23F /* Watchlist.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E411A625BEE03000A9C23F /* Watchlist.swift */; }; + 95E411B625BEE84E00A9C23F /* Stock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E411B525BEE84E00A9C23F /* Stock.swift */; }; 95F6C2F025BAE2ED003CF389 /* Company.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F6C2EF25BAE2ED003CF389 /* Company.swift */; }; - 95F6C2F325BAE3D1003CF389 /* Stock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F6C2F225BAE3D1003CF389 /* Stock.swift */; }; - 95F6C2FE25BAEBBD003CF389 /* HeaderWatchList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F6C2FD25BAEBBD003CF389 /* HeaderWatchList.swift */; }; 95F6C30125BAEC8B003CF389 /* CompanyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F6C30025BAEC8B003CF389 /* CompanyView.swift */; }; 95F6C30525BAF599003CF389 /* CompanyHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F6C30425BAF599003CF389 /* CompanyHeader.swift */; }; 95F6C30925BAF7C2003CF389 /* DateSelection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F6C30825BAF7C2003CF389 /* DateSelection.swift */; }; - 95F6C31125BAFFB8003CF389 /* AddWatchlist.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F6C31025BAFFB8003CF389 /* AddWatchlist.swift */; }; 95F7CAF625ADC7B7009E0E7C /* LazyBear.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 95F7CAF425ADC7B7009E0E7C /* LazyBear.xcdatamodeld */; }; /* End PBXBuildFile section */ @@ -50,7 +46,6 @@ 95002578256D1564008FFD28 /* Configuration.storekit */ = {isa = PBXFileReference; lastKnownFileType = text; path = Configuration.storekit; sourceTree = "<group>"; }; 9500257F256D17D9008FFD28 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; }; 950B79F525B1CB7A00E5DB5B /* CompanyList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompanyList.swift; sourceTree = "<group>"; }; - 952498B225BB381300B00E22 /* CurrentPrice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrentPrice.swift; sourceTree = "<group>"; }; 952498B525BB47A700B00E22 /* LatestPriceModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = LatestPriceModel.swift; path = lazybear/Models/LatestPriceModel.swift; sourceTree = SOURCE_ROOT; }; 9537923525BDF85D0001F82B /* GoogleApi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = GoogleApi.swift; path = lazybear/GoogleApi.swift; sourceTree = SOURCE_ROOT; }; 9537924925BDFCD70001F82B /* LoadImageTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = LoadImageTest.swift; path = lazybear/Tests/LoadImageTest.swift; sourceTree = SOURCE_ROOT; }; @@ -60,7 +55,7 @@ 95700BC525BD9D12009CEEFE /* IexApi.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = IexApi.swift; path = lazybear/IexApi.swift; sourceTree = SOURCE_ROOT; }; 95AB4A79259DCBAE0064C9C1 /* ReadJson.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ReadJson.swift; path = lazybear/Functions/ReadJson.swift; sourceTree = SOURCE_ROOT; }; 95AB4A7C259DCC0C0064C9C1 /* CompanyModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CompanyModel.swift; path = lazybear/Models/CompanyModel.swift; sourceTree = SOURCE_ROOT; }; - 95AB4A8F259DD66D0064C9C1 /* CompanyRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompanyRow.swift; sourceTree = "<group>"; }; + 95AB4A8F259DD66D0064C9C1 /* Row.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Row.swift; sourceTree = "<group>"; }; 95B04EAF25212369000AD27F /* LazyBear.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LazyBear.app; sourceTree = BUILT_PRODUCTS_DIR; }; 95B04EB225212369000AD27F /* LazyBearApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazyBearApp.swift; sourceTree = "<group>"; }; 95B04EB425212369000AD27F /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; }; @@ -73,17 +68,14 @@ 95E0287A25B88F3C00020CF2 /* FormDescription.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = FormDescription.swift; path = lazybear/Models/FormDescription.swift; sourceTree = SOURCE_ROOT; }; 95E4119125BEC56F00A9C23F /* Header.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Header.swift; sourceTree = "<group>"; }; 95E4119525BEC9DD00A9C23F /* TestViewBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestViewBuilder.swift; path = lazybear/Tests/TestViewBuilder.swift; sourceTree = SOURCE_ROOT; }; - 95E4119925BECCB200A9C23F /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Model.swift; path = lazybear/Functions/Model.swift; sourceTree = SOURCE_ROOT; }; 95E411A025BEDDC400A9C23F /* WatchlistCompany+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WatchlistCompany+CoreDataClass.swift"; sourceTree = "<group>"; }; 95E411A125BEDDC400A9C23F /* WatchlistCompany+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WatchlistCompany+CoreDataProperties.swift"; sourceTree = "<group>"; }; - 95F6C2E325BAD529003CF389 /* RandomColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = RandomColor.swift; path = lazybear/Functions/RandomColor.swift; sourceTree = SOURCE_ROOT; }; + 95E411A625BEE03000A9C23F /* Watchlist.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Watchlist.swift; sourceTree = "<group>"; }; + 95E411B525BEE84E00A9C23F /* Stock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Stock.swift; sourceTree = "<group>"; }; 95F6C2EF25BAE2ED003CF389 /* Company.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Company.swift; sourceTree = "<group>"; }; - 95F6C2F225BAE3D1003CF389 /* Stock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Stock.swift; sourceTree = "<group>"; }; - 95F6C2FD25BAEBBD003CF389 /* HeaderWatchList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeaderWatchList.swift; sourceTree = "<group>"; }; 95F6C30025BAEC8B003CF389 /* CompanyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CompanyView.swift; path = "lazybear/Supply views/CompanyView.swift"; sourceTree = SOURCE_ROOT; }; 95F6C30425BAF599003CF389 /* CompanyHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompanyHeader.swift; sourceTree = "<group>"; }; 95F6C30825BAF7C2003CF389 /* DateSelection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateSelection.swift; sourceTree = "<group>"; }; - 95F6C31025BAFFB8003CF389 /* AddWatchlist.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddWatchlist.swift; sourceTree = "<group>"; }; 95F7CAF525ADC7B7009E0E7C /* LazyBear.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = LazyBear.xcdatamodel; sourceTree = "<group>"; }; /* End PBXFileReference section */ @@ -122,17 +114,15 @@ isa = PBXGroup; children = ( 95E4119125BEC56F00A9C23F /* Header.swift */, - 95AB4A8F259DD66D0064C9C1 /* CompanyRow.swift */, + 95612C4F2598D48200F7698F /* SearchBar.swift */, + 95E411A625BEE03000A9C23F /* Watchlist.swift */, + 95AB4A8F259DD66D0064C9C1 /* Row.swift */, 950B79F525B1CB7A00E5DB5B /* CompanyList.swift */, - 95F6C2F225BAE3D1003CF389 /* Stock.swift */, - 95F6C2EF25BAE2ED003CF389 /* Company.swift */, 95F6C30025BAEC8B003CF389 /* CompanyView.swift */, - 95612C4F2598D48200F7698F /* SearchBar.swift */, - 95F6C2FD25BAEBBD003CF389 /* HeaderWatchList.swift */, + 95F6C2EF25BAE2ED003CF389 /* Company.swift */, + 95E411B525BEE84E00A9C23F /* Stock.swift */, 95F6C30425BAF599003CF389 /* CompanyHeader.swift */, - 952498B225BB381300B00E22 /* CurrentPrice.swift */, 95F6C30825BAF7C2003CF389 /* DateSelection.swift */, - 95F6C31025BAFFB8003CF389 /* AddWatchlist.swift */, ); name = "Supply views"; path = "lazybear/Supply views"; @@ -142,10 +132,8 @@ isa = PBXGroup; children = ( 95AB4A79259DCBAE0064C9C1 /* ReadJson.swift */, - 95F6C2E325BAD529003CF389 /* RandomColor.swift */, 95C28AB525BC45CF0033D16A /* ChartStyle.swift */, 95C28AB825BC46250033D16A /* ScalateChart.swift */, - 95E4119925BECCB200A9C23F /* Model.swift */, ); path = Functions; sourceTree = "<group>"; @@ -299,32 +287,28 @@ 95E0287B25B88F3C00020CF2 /* FormDescription.swift in Sources */, 952498B625BB47A700B00E22 /* LatestPriceModel.swift in Sources */, 95F6C30525BAF599003CF389 /* CompanyHeader.swift in Sources */, - 952498B325BB381300B00E22 /* CurrentPrice.swift in Sources */, - 95F6C2FE25BAEBBD003CF389 /* HeaderWatchList.swift in Sources */, - 95E4119A25BECCB200A9C23F /* Model.swift in Sources */, 95E411A225BEDDC400A9C23F /* WatchlistCompany+CoreDataClass.swift in Sources */, 95612C512598D48200F7698F /* SearchBar.swift in Sources */, 95E411A325BEDDC400A9C23F /* WatchlistCompany+CoreDataProperties.swift in Sources */, 950B79F625B1CB7A00E5DB5B /* CompanyList.swift in Sources */, 95B04EB525212369000AD27F /* ContentView.swift in Sources */, - 95AB4A90259DD66D0064C9C1 /* CompanyRow.swift in Sources */, + 95AB4A90259DD66D0064C9C1 /* Row.swift in Sources */, 95F6C30125BAEC8B003CF389 /* CompanyView.swift in Sources */, 95F6C30925BAF7C2003CF389 /* DateSelection.swift in Sources */, 95F6C2F025BAE2ED003CF389 /* Company.swift in Sources */, 95D1BF4925ADCF7700E5D063 /* Persistence.swift in Sources */, 95E4119225BEC56F00A9C23F /* Header.swift in Sources */, - 95F6C31125BAFFB8003CF389 /* AddWatchlist.swift in Sources */, 95B04EB325212369000AD27F /* LazyBearApp.swift in Sources */, - 95F6C2F325BAE3D1003CF389 /* Stock.swift in Sources */, 95AB4A7D259DCC0C0064C9C1 /* CompanyModel.swift in Sources */, 95700BC625BD9D12009CEEFE /* IexApi.swift in Sources */, 9537923625BDF85D0001F82B /* GoogleApi.swift in Sources */, - 95F6C2E425BAD529003CF389 /* RandomColor.swift in Sources */, 95C28AB625BC45CF0033D16A /* ChartStyle.swift in Sources */, 9537924A25BDFCD70001F82B /* LoadImageTest.swift in Sources */, 954D997125A253A9001F7F60 /* Config.swift in Sources */, 95C28AB925BC46250033D16A /* ScalateChart.swift in Sources */, + 95E411B625BEE84E00A9C23F /* Stock.swift in Sources */, 954D992525A2123B001F7F60 /* HistoricalPricesModel.swift in Sources */, + 95E411A725BEE03000A9C23F /* Watchlist.swift in Sources */, 95F7CAF625ADC7B7009E0E7C /* LazyBear.xcdatamodeld in Sources */, 95E4119625BEC9DD00A9C23F /* TestViewBuilder.swift in Sources */, );
Binary file LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed
--- a/lazybear/ContentView.swift Mon Jan 25 12:07:09 2021 +0100 +++ b/lazybear/ContentView.swift Mon Jan 25 12:53:30 2021 +0100 @@ -22,8 +22,9 @@ if searchedCompany.count > 2 { CompanyList(searchedCompany: $searchedCompany) } + Spacer() } else { - // Watchlist + Watchlist() } } }
--- a/lazybear/Core Data/Persistence.swift Mon Jan 25 12:07:09 2021 +0100 +++ b/lazybear/Core Data/Persistence.swift Mon Jan 25 12:53:30 2021 +0100 @@ -13,12 +13,22 @@ static var preview: PersistenceController = { let result = PersistenceController(inMemory: true) let viewContext = result.container.viewContext - for _ in 0..<10 { - let newItem = FavCompany(context: viewContext) - newItem.cik = 123 - newItem.symbol = "Symbol" - newItem.name = "Name" - + for _ in 0..<13 { + let newItem = WatchlistCompany(context: viewContext) + newItem.symbol = String() + newItem.exchange = String() + newItem.exchangeSuffix = String() + newItem.exchangeName = String() + newItem.name = String() + newItem.date = String() + newItem.type = String() + newItem.iexId = String() + newItem.region = String() + newItem.currency = String() + newItem.isEnabled = Bool() + newItem.figi = String() + newItem.cik = String() + newItem.lei = String() } do { try viewContext.save()
--- a/lazybear/Functions/Model.swift Mon Jan 25 12:07:09 2021 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -// -// ModelSelected.swift -// LazyBear -// -// Created by Dennis Concepción Martín on 25/1/21. -// - -import SwiftUI - -class Model { - func selector() { - - } -}
--- a/lazybear/Functions/RandomColor.swift Mon Jan 25 12:07:09 2021 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -// -// RandomColor.swift -// LazyBear -// -// Created by Dennis Concepción Martín on 22/1/21. -// - -import SwiftUI - -func randomColor(index: Int) -> Color { - let systemColour: [Color] = [Color(.systemBlue), Color(.systemRed), Color(.systemPink), Color(.systemTeal), Color(.systemGreen), Color(.systemOrange), Color(.systemYellow), Color(.systemPurple), Color(.systemIndigo), Color(.systemGray)] - - var index = index - if index > 10 { index = index/10 } - if index > 100 { index = index/100 } - if index > 1000 { index = index/1000 } - if index > 10000 { index = index/10000 } - - let color = systemColour[index] - - return color -}
--- a/lazybear/LazyBearApp.swift Mon Jan 25 12:07:09 2021 +0100 +++ b/lazybear/LazyBearApp.swift Mon Jan 25 12:53:30 2021 +0100 @@ -13,7 +13,7 @@ var body: some Scene { WindowGroup { - LoadImageTest() + ContentView() .environment(\.managedObjectContext, persistenceController.container.viewContext) } }
--- a/lazybear/Supply views/AddWatchlist.swift Mon Jan 25 12:07:09 2021 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -// -// AddWatchlist.swift -// LazyBear -// -// Created by Dennis Concepción Martín on 22/1/21. -// - -import SwiftUI - -struct AddWatchlist: View { - @Environment(\.managedObjectContext) private var viewContext - @FetchRequest(entity: FavCompany.entity(), sortDescriptors: []) - var favCompanies: FetchedResults<FavCompany> - - var body: some View { - Button(action: { }) { - Text("Add to watchlist") - } - } - - func addWatchlist(cik: Int, symbol: String, name: String) { - let favCompany = FavCompany(context: viewContext) - favCompany.cik = Int32(cik) - favCompany.symbol = symbol - favCompany.name = name - do { - try viewContext.save() - print("Company saved.") - } catch { - print(error.localizedDescription) - } - } -} - -struct AddWatchlist_Previews: PreviewProvider { - static var previews: some View { - AddWatchlist() - } -}
--- a/lazybear/Supply views/Company.swift Mon Jan 25 12:07:09 2021 +0100 +++ b/lazybear/Supply views/Company.swift Mon Jan 25 12:53:30 2021 +0100 @@ -15,8 +15,7 @@ CompanyHeader(name: self.name, symbol: self.symbol) ScrollView { VStack(alignment: .leading) { - //Stock(name: self.name, symbol: self.symbol) - Spacer() + // Stock() } } }
--- a/lazybear/Supply views/CompanyList.swift Mon Jan 25 12:07:09 2021 +0100 +++ b/lazybear/Supply views/CompanyList.swift Mon Jan 25 12:53:30 2021 +0100 @@ -14,7 +14,7 @@ List { ForEach(companiesData.filter({ searchedCompany.isEmpty ? true : $0.name.localizedStandardContains(searchedCompany) }) , id: \.symbol) { company in - //CompanyRow(company: company) + CompanyRow(company: company) } } .edgesIgnoringSafeArea(.bottom)
--- a/lazybear/Supply views/CompanyRow.swift Mon Jan 25 12:07:09 2021 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -// -// CompanyRown.swift -// LazyBear -// -// Created by Dennis Concepción Martín on 31/12/20. -// - -import SwiftUI - -struct CompanyRow: View { - @ObservedObject var companyView = CompanyView() - var company: CompanyModel - var favCompany: FavCompany - - var body: some View { - Button(action: { companyView.isShowing.toggle() }) { - VStack(alignment: .leading) { - Text(company.symbol.uppercased()) - .fontWeight(.semibold) - - Text(company.name.capitalized) - .font(.caption) - - } - } - .fullScreenCover(isPresented: $companyView.isShowing) { - Company(name: company.name, symbol: company.symbol) - } - } -} - -struct CompanyRown_Previews: PreviewProvider { - static var previews: some View { - CompanyRow(company: companiesData[0], favCompany: FavCompany.init()) - } -}
--- a/lazybear/Supply views/CurrentPrice.swift Mon Jan 25 12:07:09 2021 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -// -// CurrentPrice.swift -// LazyBear -// -// Created by Dennis Concepción Martín on 22/1/21. -// - -import SwiftUI - -struct CurrentPrice: View { - @State var price: Double - @State var change: Double - @State var marketIsOpen: Bool - - var body: some View { - HStack { - Text("\(price, specifier: "%.2f")") - .font(.headline) - .padding(.trailing) - - Text("\(change, specifier: "%.2f")%") - .foregroundColor(.green) - - Spacer() - AddWatchlist() - } - .padding([.leading, .trailing]) - } -} - -struct CurrentPrice_Previews: PreviewProvider { - static var previews: some View { - CurrentPrice(price: 100.50, change: 1.35, marketIsOpen: true) - } -}
--- a/lazybear/Supply views/HeaderWatchList.swift Mon Jan 25 12:07:09 2021 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -// -// HeaderWatchList.swift -// LazyBear -// -// Created by Dennis Concepción Martín on 22/1/21. -// - -import SwiftUI - -struct HeaderWatchlist: View { - var body: some View { - HStack(alignment: .bottom) { - Text("Watchlist") - .font(.title2) - .fontWeight(.semibold) - .padding([.top, .leading]) - - Spacer() - EditButton() - .padding(.trailing) - } - } -} - -struct HeaderWatchlist_Previews: PreviewProvider { - static var previews: some View { - HeaderWatchlist() - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lazybear/Supply views/Row.swift Mon Jan 25 12:53:30 2021 +0100 @@ -0,0 +1,53 @@ +// +// CompanyRown.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 31/12/20. +// + +import SwiftUI + +struct CompanyRow: View { + @ObservedObject var companyView = CompanyView() + var company: CompanyModel + + var body: some View { + Button(action: { companyView.isShowing.toggle() }) { + VStack(alignment: .leading) { + Text(company.symbol.uppercased()) + .fontWeight(.semibold) + + Text(company.name.capitalized) + .font(.caption) + + } + } + .fullScreenCover(isPresented: $companyView.isShowing) { + Company(name: company.name, symbol: company.symbol) + } + } +} + +struct CompanyRown_Previews: PreviewProvider { + static var previews: some View { + CompanyRow(company: companiesData[0]) + } +} + +struct WatchlistRow: View { + @ObservedObject var companyView = CompanyView() + var company: WatchlistCompany + + var body: some View { + Button(action: { companyView.isShowing.toggle() }) { + VStack(alignment: .leading) { + Text(company.symbol!.uppercased()) + .fontWeight(.semibold) + + Text(company.name!.capitalized) + .font(.caption) + + } + } + } +}
--- a/lazybear/Supply views/Stock.swift Mon Jan 25 12:07:09 2021 +0100 +++ b/lazybear/Supply views/Stock.swift Mon Jan 25 12:53:30 2021 +0100 @@ -1,67 +1,34 @@ // -// Price.swift +// Stock.swift // LazyBear // -// Created by Dennis Concepción Martín on 22/1/21. +// Created by Dennis Concepción Martín on 25/1/21. // import SwiftUI -import SwiftUICharts -/* + struct Stock: View { - @ObservedObject var historicalPrices = HistoricalPrices() - @ObservedObject var latestPrice = LatestPrice() - - var periods = ["1D", "1W", "1M", "3M", "6M", "1Y", "2Y", "5Y"] - @State var selectedPeriod = 3 - var name: String - var symbol: String + @Environment(\.managedObjectContext) private var viewContext var body: some View { - VStack { - Divider() - - let price = latestPrice.latestPrice - let change = latestPrice.changePercent*100 - //let marketIsOpen = latestPrice.isUSMarketOpen - - if latestPrice.showingView { - CurrentPrice(price: price, change: change, marketIsOpen: false) - } else { - HStack { - ProgressView() - .padding(.leading) - Spacer() - } - } - - Divider() - DateSelection(selectedperiod: $selectedPeriod) - .padding([.leading, .trailing]) - .onChange(of: selectedPeriod, perform: { value in - historicalPrices.showingView.toggle() - historicalPrices.request(symbol: self.symbol, period: periods[selectedPeriod], sandbox: true) - }) - - if historicalPrices.showingView { - let prices = historicalPrices.result.map { $0.close } - LineView(data: scalateChart(prices: prices, selectedPeriod: selectedPeriod), title: "", style: chartStyle()) - .padding([.leading, .trailing]) - .offset(y: -40) - } else { - ProgressView() - } - } - .onAppear { - historicalPrices.request(symbol: self.symbol, period: periods[selectedPeriod], sandbox: true) - latestPrice.request(symbol: self.symbol, sandbox: true) + Text("Hello, World!") + } + + func addWatchlist(name: String, symbol: String) { + let watchlistCompany = WatchlistCompany(context: viewContext) + watchlistCompany.name = name + watchlistCompany.symbol = symbol + do { + try viewContext.save() + print("Company saved.") + } catch { + print(error.localizedDescription) } } } -struct Price_Previews: PreviewProvider { +struct Stock_Previews: PreviewProvider { static var previews: some View { - Stock(name: "Apple Inc", symbol: "AAPL") + Stock() } } -*/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lazybear/Supply views/Watchlist.swift Mon Jan 25 12:53:30 2021 +0100 @@ -0,0 +1,43 @@ +// +// Watchlist.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 25/1/21. +// + +import SwiftUI + +struct Watchlist: View { + @Environment(\.managedObjectContext) private var viewContext // Core data + @FetchRequest(entity: WatchlistCompany.entity(), sortDescriptors: []) // Core data + var companies: FetchedResults<WatchlistCompany> // Fetch core data + + var body: some View { + List { + ForEach(companies) { company in + WatchlistRow(company: company) + + } + // Delete from persistent storage + .onDelete { indexSet in delete(indexSet: indexSet) } + } + } + + func delete(indexSet: IndexSet) { + for index in indexSet { + viewContext.delete(companies[index]) + } + do { + try viewContext.save() + print("Company deleted") + } catch { + print(error.localizedDescription) + } + } +} + +struct Watchlist_Previews: PreviewProvider { + static var previews: some View { + Watchlist() + } +}