swiftui

UI changes with ObservableObject just after switching tabs

送分小仙女□ 提交于 2021-02-11 16:51:33
问题 I have a ObservableObject that I use to update my UI when new data is sent from the server (an a class which contains an array of custom structs). For some reason, when the data is sent, the ContentView 's body is called, but the data isn't changed. I even added a print statement to check if the data that the array contains is right and it is. When I try to switch to another tab on my TabView , and then switch back to the main view, the UI does get updated. Does anybody know why the UI

UI changes with ObservableObject just after switching tabs

烈酒焚心 提交于 2021-02-11 16:51:24
问题 I have a ObservableObject that I use to update my UI when new data is sent from the server (an a class which contains an array of custom structs). For some reason, when the data is sent, the ContentView 's body is called, but the data isn't changed. I even added a print statement to check if the data that the array contains is right and it is. When I try to switch to another tab on my TabView , and then switch back to the main view, the UI does get updated. Does anybody know why the UI

UI changes with ObservableObject just after switching tabs

若如初见. 提交于 2021-02-11 16:50:43
问题 I have a ObservableObject that I use to update my UI when new data is sent from the server (an a class which contains an array of custom structs). For some reason, when the data is sent, the ContentView 's body is called, but the data isn't changed. I even added a print statement to check if the data that the array contains is right and it is. When I try to switch to another tab on my TabView , and then switch back to the main view, the UI does get updated. Does anybody know why the UI

UI changes with ObservableObject just after switching tabs

怎甘沉沦 提交于 2021-02-11 16:49:36
问题 I have a ObservableObject that I use to update my UI when new data is sent from the server (an a class which contains an array of custom structs). For some reason, when the data is sent, the ContentView 's body is called, but the data isn't changed. I even added a print statement to check if the data that the array contains is right and it is. When I try to switch to another tab on my TabView , and then switch back to the main view, the UI does get updated. Does anybody know why the UI

fetchRequest is null when calling second time

和自甴很熟 提交于 2021-02-11 15:56:20
问题 The code is let request: NSFetchRequest<NSFetchRequestResult> = Item.fetchRequest() print(request) Item is an entity of Core Data. The first execution is correct, but when execute it again error occurs Thread 12: EXC_BAD_ACCESS (code=1, address=0x0) . The following is logs: This is a similar question, but with Object C. It says that defining managedObjectContext in view controller directly instead of transferring it from AppDelegate can fix the bug. In my code, the managedObjectContext is in

fetchRequest is null when calling second time

允我心安 提交于 2021-02-11 15:55:28
问题 The code is let request: NSFetchRequest<NSFetchRequestResult> = Item.fetchRequest() print(request) Item is an entity of Core Data. The first execution is correct, but when execute it again error occurs Thread 12: EXC_BAD_ACCESS (code=1, address=0x0) . The following is logs: This is a similar question, but with Object C. It says that defining managedObjectContext in view controller directly instead of transferring it from AppDelegate can fix the bug. In my code, the managedObjectContext is in

Applying gradient to UIBezierPath in SwiftUI Shape

末鹿安然 提交于 2021-02-11 15:45:50
问题 I'm trying to accomplish the following: struct MultiSegmentPaths: Shape { func path(in rect: CGRect) -> Path { let path1 = UIBezierPath() // apply gradient to path 1 let path2 = UIBezierPath() // apply gradient to path 2 return Path(path1.append(path2).cgPath) } } Now I thought I could wrap each segment with Path , but that returns some View which means I can't append the two together. And applying a gradient directly to UIBezierPath requires having access to context - which isn't passed in

SwiftUI open view with data or only with a reference to Firestore document

房东的猫 提交于 2021-02-11 15:39:20
问题 I need to open a view called PackageDetails . There are two cases in which this view could be opened. 1. If you tap a specific Package from a list of packages. I have an array of all the packages. So I'm passing the specific struct from this list and I'm opening this package view. PackageDetail(package: package) . I already have all the data I need so I do not need to make an extra call to Firestore to fetch this document. 2. Package view can be opened by a link from some other view in this

SwiftUI open view with data or only with a reference to Firestore document

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-11 15:38:59
问题 I need to open a view called PackageDetails . There are two cases in which this view could be opened. 1. If you tap a specific Package from a list of packages. I have an array of all the packages. So I'm passing the specific struct from this list and I'm opening this package view. PackageDetail(package: package) . I already have all the data I need so I do not need to make an extra call to Firestore to fetch this document. 2. Package view can be opened by a link from some other view in this

How to get a simple SwiftUI to load as a UITableView would (logically!)

荒凉一梦 提交于 2021-02-11 15:16:03
问题 How can I get SwiftUI to load 8 images horizontally but if the third image happens to go off screen it puts it in a Vstack underneath the 1st image with the same padding... and if three can fit on the screen it does the same to the 4th. I can not find anyway to do this! TableViews were so easy to implement but now SwiftUI makes things much harder iPhone: [1] [2] [3] [4] [5] [6] [7] [8] iPad Pro [1] [2][3] [4] [5] [6] [7] [8] iPad Mini [1] [2][3] [4] [5] [6] [7] [8] 回答1: I have acheived this