Mercurial > public > lazybear
changeset 83:fce6e0364c1c
Fix preview core data crashing
author | Dennis Concepción Martín <66180929+denniscm190@users.noreply.github.com> |
---|---|
date | Mon, 25 Jan 2021 13:06:24 +0100 |
parents | 0730f031e478 |
children | 6ae5b2191c54 |
files | LazyBear.xcodeproj/project.pbxproj LazyBear.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate lazybear/Supply views/CompanyRow.swift lazybear/Supply views/Row.swift lazybear/Supply views/Title.swift lazybear/Supply views/Watchlist.swift lazybear/Supply views/WatchlistRow.swift |
diffstat | 7 files changed, 109 insertions(+), 59 deletions(-) [+] |
line wrap: on
line diff
--- a/LazyBear.xcodeproj/project.pbxproj Mon Jan 25 12:53:30 2021 +0100 +++ b/LazyBear.xcodeproj/project.pbxproj Mon Jan 25 13:06:24 2021 +0100 @@ -19,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 /* Row.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95AB4A8F259DD66D0064C9C1 /* Row.swift */; }; + 95AB4A90259DD66D0064C9C1 /* CompanyRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95AB4A8F259DD66D0064C9C1 /* CompanyRow.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 */; }; @@ -35,6 +35,8 @@ 95E411A325BEDDC400A9C23F /* WatchlistCompany+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E411A125BEDDC400A9C23F /* WatchlistCompany+CoreDataProperties.swift */; }; 95E411A725BEE03000A9C23F /* Watchlist.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E411A625BEE03000A9C23F /* Watchlist.swift */; }; 95E411B625BEE84E00A9C23F /* Stock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E411B525BEE84E00A9C23F /* Stock.swift */; }; + 95E411BA25BEEA4400A9C23F /* Title.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E411B925BEEA4400A9C23F /* Title.swift */; }; + 95E411BE25BEEA6C00A9C23F /* WatchlistRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E411BD25BEEA6C00A9C23F /* WatchlistRow.swift */; }; 95F6C2F025BAE2ED003CF389 /* Company.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F6C2EF25BAE2ED003CF389 /* Company.swift */; }; 95F6C30125BAEC8B003CF389 /* CompanyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F6C30025BAEC8B003CF389 /* CompanyView.swift */; }; 95F6C30525BAF599003CF389 /* CompanyHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95F6C30425BAF599003CF389 /* CompanyHeader.swift */; }; @@ -55,7 +57,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 /* Row.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Row.swift; sourceTree = "<group>"; }; + 95AB4A8F259DD66D0064C9C1 /* CompanyRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompanyRow.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>"; }; @@ -72,6 +74,8 @@ 95E411A125BEDDC400A9C23F /* WatchlistCompany+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WatchlistCompany+CoreDataProperties.swift"; sourceTree = "<group>"; }; 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>"; }; + 95E411B925BEEA4400A9C23F /* Title.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Title.swift; sourceTree = "<group>"; }; + 95E411BD25BEEA6C00A9C23F /* WatchlistRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchlistRow.swift; sourceTree = "<group>"; }; 95F6C2EF25BAE2ED003CF389 /* Company.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Company.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>"; }; @@ -116,13 +120,15 @@ 95E4119125BEC56F00A9C23F /* Header.swift */, 95612C4F2598D48200F7698F /* SearchBar.swift */, 95E411A625BEE03000A9C23F /* Watchlist.swift */, - 95AB4A8F259DD66D0064C9C1 /* Row.swift */, + 95AB4A8F259DD66D0064C9C1 /* CompanyRow.swift */, + 95E411BD25BEEA6C00A9C23F /* WatchlistRow.swift */, 950B79F525B1CB7A00E5DB5B /* CompanyList.swift */, 95F6C30025BAEC8B003CF389 /* CompanyView.swift */, 95F6C2EF25BAE2ED003CF389 /* Company.swift */, 95E411B525BEE84E00A9C23F /* Stock.swift */, 95F6C30425BAF599003CF389 /* CompanyHeader.swift */, 95F6C30825BAF7C2003CF389 /* DateSelection.swift */, + 95E411B925BEEA4400A9C23F /* Title.swift */, ); name = "Supply views"; path = "lazybear/Supply views"; @@ -289,10 +295,11 @@ 95F6C30525BAF599003CF389 /* CompanyHeader.swift in Sources */, 95E411A225BEDDC400A9C23F /* WatchlistCompany+CoreDataClass.swift in Sources */, 95612C512598D48200F7698F /* SearchBar.swift in Sources */, + 95E411BE25BEEA6C00A9C23F /* WatchlistRow.swift in Sources */, 95E411A325BEDDC400A9C23F /* WatchlistCompany+CoreDataProperties.swift in Sources */, 950B79F625B1CB7A00E5DB5B /* CompanyList.swift in Sources */, 95B04EB525212369000AD27F /* ContentView.swift in Sources */, - 95AB4A90259DD66D0064C9C1 /* Row.swift in Sources */, + 95AB4A90259DD66D0064C9C1 /* CompanyRow.swift in Sources */, 95F6C30125BAEC8B003CF389 /* CompanyView.swift in Sources */, 95F6C30925BAF7C2003CF389 /* DateSelection.swift in Sources */, 95F6C2F025BAE2ED003CF389 /* Company.swift in Sources */, @@ -309,6 +316,7 @@ 95E411B625BEE84E00A9C23F /* Stock.swift in Sources */, 954D992525A2123B001F7F60 /* HistoricalPricesModel.swift in Sources */, 95E411A725BEE03000A9C23F /* Watchlist.swift in Sources */, + 95E411BA25BEEA4400A9C23F /* Title.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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lazybear/Supply views/CompanyRow.swift Mon Jan 25 13:06:24 2021 +0100 @@ -0,0 +1,35 @@ +// +// 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]) + } +}
--- a/lazybear/Supply views/Row.swift Mon Jan 25 12:53:30 2021 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +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 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) - - } - } - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lazybear/Supply views/Title.swift Mon Jan 25 13:06:24 2021 +0100 @@ -0,0 +1,20 @@ +// +// Title.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 25/1/21. +// + +import SwiftUI + +struct Title: View { + var body: some View { + Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + } +} + +struct Title_Previews: PreviewProvider { + static var previews: some View { + Title() + } +}
--- a/lazybear/Supply views/Watchlist.swift Mon Jan 25 12:53:30 2021 +0100 +++ b/lazybear/Supply views/Watchlist.swift Mon Jan 25 13:06:24 2021 +0100 @@ -14,16 +14,17 @@ var body: some View { List { + EditButton() ForEach(companies) { company in WatchlistRow(company: company) } // Delete from persistent storage - .onDelete { indexSet in delete(indexSet: indexSet) } + .onDelete { indexSet in deleteWatchlist(indexSet: indexSet) } } } - func delete(indexSet: IndexSet) { + func deleteWatchlist(indexSet: IndexSet) { for index in indexSet { viewContext.delete(companies[index]) }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lazybear/Supply views/WatchlistRow.swift Mon Jan 25 13:06:24 2021 +0100 @@ -0,0 +1,39 @@ +// +// WatchlistRow.swift +// LazyBear +// +// Created by Dennis Concepción Martín on 25/1/21. +// + +import SwiftUI +import CoreData + +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) + + } + } + } +} + +struct WatchlistRow_Previews: PreviewProvider { + // Avoid preview crashing + static let moc = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType) + + static var previews: some View { + let watchlistCompany = WatchlistCompany(context: moc) + watchlistCompany.name = "apple inc" + watchlistCompany.symbol = "aapl" + return WatchlistRow(company: watchlistCompany) + } +}