swiftui

How to get the index of a deleted row from a list in SwiftUI?

萝らか妹 提交于 2021-02-20 18:47:14
问题 I want to delete an element from an array that I am displaying as a list using a ForEach , but I also need to send a HTTP request to a REST API and I need to put the index of the element in the body of the request. Here is my code: ForEach(self.symptoms, id: \.self) { symptom in VStack(alignment: .leading) { Text(symptom) } }.onDelete(perform: delete) Here is the delete function: func delete(at offsets: IndexSet) { self.symptoms.remove(atOffsets: offsets) // here I want to make the HTTP

How to get the index of a deleted row from a list in SwiftUI?

坚强是说给别人听的谎言 提交于 2021-02-20 18:44:48
问题 I want to delete an element from an array that I am displaying as a list using a ForEach , but I also need to send a HTTP request to a REST API and I need to put the index of the element in the body of the request. Here is my code: ForEach(self.symptoms, id: \.self) { symptom in VStack(alignment: .leading) { Text(symptom) } }.onDelete(perform: delete) Here is the delete function: func delete(at offsets: IndexSet) { self.symptoms.remove(atOffsets: offsets) // here I want to make the HTTP

The iOS 13.0 simulator runtime is not available

北慕城南 提交于 2021-02-20 06:25:24
问题 I installed the Xcode-11-beta along with macOS 10.15 beta. At first I can play with SwiftUI preview normally. But after I tried to move the Xcode-beta from the ~/Downloads directory where I initially installed it, to /Applications , the preview can't work. Here is the error: So I moved it back to ~/Downloads , hoping things will go well as before. But it gives the same error. After this, I reinstalled it and I still got this error. Can anyone help me fix it? The content of diagnostics report

SwiftUI: Switch .sheet on enum, does not work

做~自己de王妃 提交于 2021-02-20 02:51:10
问题 I have two Modal/Popover .sheet 's I would like to show based on which button is pressed by a user. I have setup an enum with the different choices and set a default choice. Expected behaviour: When the user selects any choice, the right sheet is displayed. When the user THEN selects the other choice, it also shows the correct sheet. Observed behaviour: In the example below, when the user first picks the second choice , the first sheet is shown and will continue to show until the user selects

Using a SwiftUI List Sidebar in a UISplitViewController

醉酒当歌 提交于 2021-02-20 00:40:30
问题 I am attempting to build my app's navigation such that I have a UISplitViewController (triple column style) with my views built with SwiftUI. My Primary Sidebar is currently quite simple: struct PrimarySidebarView: View { @EnvironmentObject var appModel: AppModel var body: some View { List(PrimarySidebarSelection.allCases, id: \.self, selection: $appModel.primarySidebarSelection) { selection in Text(selection.rawValue) } .listStyle(SidebarListStyle()) .navigationBarItems(trailing: EditButton(

How to change color of ToolbarItem with navigationBarLeading placement in SwiftUI

三世轮回 提交于 2021-02-19 09:24:31
问题 I need a title to be on the left side of a navigation bar. I use the following code: .toolbar { ToolbarItem(placement: .navigationBarLeading) { Text("Title") .foregroundColor(.black) } } The problem is that it is displayed blue and as a button. Is it possible to change its color to black somehow? foregroundColor , accentColor do not work. Also, I tried to use a disabled button with Text("Title") inside. But it was displayed grey in that case. Not color, nor PlainButtonStyle were applied. 回答1:

How do I save and load ARWorldMap in SwiftUI app?

岁酱吖の 提交于 2021-02-19 05:38:26
问题 I followed a YouTube tutorial on how to place virtual Models in SwiftUI. Now that I can place my Models, I would like to save and load the models position. I have already made 2 Buttons for save and load, but I don't know the correct code to save and load the Entities and Anchors. The following code is inside my updateUIView function: func updateUIView(_ uiView: ARView, context: Context) { if let name = self.modelName { print("Modell mit dem Namen \(name) wurde zum plaziert") let filename =

How to refresh multiple timers in widget iOS14?

自古美人都是妖i 提交于 2021-02-19 04:19:31
问题 I'm currently developing an application using SwiftUI and trying to make a widget iOS 14 users can check a list of timers. This Widget has multiple Text(Data(),style: .timer) to show some date data as timer. and when the rest of the value for the timer is over, I want to show it like this 00:00 . So I implemented some way in getTimeline function referring to this article SwiftUI iOS 14 Widget CountDown But I don't know how can I do it the same way for multiple timers... In the case of my code

How to refresh multiple timers in widget iOS14?

我是研究僧i 提交于 2021-02-19 04:18:40
问题 I'm currently developing an application using SwiftUI and trying to make a widget iOS 14 users can check a list of timers. This Widget has multiple Text(Data(),style: .timer) to show some date data as timer. and when the rest of the value for the timer is over, I want to show it like this 00:00 . So I implemented some way in getTimeline function referring to this article SwiftUI iOS 14 Widget CountDown But I don't know how can I do it the same way for multiple timers... In the case of my code

SwiftUI View does not updated when ObservedObject changed

眉间皱痕 提交于 2021-02-19 04:01:51
问题 I have a content view where i'm showing a list of items using ForEach @ObservedObject var homeVM : HomeViewModel var body: some View { ScrollView (.horizontal, showsIndicators: false) { HStack(spacing: 10) { Spacer().frame(width:8) ForEach(homeVM.favoriteStores , id: \._id){ item in StoreRowOneView(storeVM: item) } Spacer().frame(width:8) } }.frame(height: 100) } And my ObservableObject contains @Published var favoriteStores = [StoreViewModel]() And StoreViewModel is defined as below class