swiftui

Dynamic Links Firebase function not being called at all Xcode 12?

痞子三分冷 提交于 2021-01-03 06:21:52
问题 So I have a dynamic link that is working in that it opens up the app when I click on it but the handling of the dynamic link doesn't happen. This is because application function seen below is never entered and I'm not sure why... func handleIncomingDynamicLink(_ dynamicLink: DynamicLink){ guard let url = dynamicLink.url else { print("That's weird. My dynamic link object has no url") return } print("Your incoming link parameter is \(url.absoluteString)") } func application(_ application:

SwiftUI, selecting a row in a List programmatically

拟墨画扇 提交于 2021-01-02 17:34:54
问题 I want to set the selected row in a List programmatically. In my example below via 2 Buttons. struct ContentView: View { @State private var selection = 2 var body: some View { VStack { List() { //List(selection: $selection) {. // does not compile Text("Line 0").tag(1) Text("Line 1").tag(1) Text("Line 2").tag(2) Text("Line 3").tag(3) Text("Line 4").tag(4) Text("Line 5").tag(5) } .listStyle(SidebarListStyle()) Text("Selected Item :\(self.selection)") HStack { Button(action: {if (self.selection

Create a SwiftUI Sidebar

我只是一个虾纸丫 提交于 2021-01-02 08:07:25
问题 I want to build a very simple iOS 14 sidebar using SwiftUI. The setup is quite simple, I have three views HomeView , LibraryView and SettingsView and an enum representing each screen. enum Screen: Hashable { case home, library, settings } My end-goal is to automatically switch between a tab view and a sidebar depending on the size class but some things don't quite work as expected. The global state is owned by the MainNavigationView , which is also the root view for my WindowGroup . struct

How to change width of Divider in SwiftUI?

半世苍凉 提交于 2021-01-02 06:53:28
问题 On few screens of my SwiftUI app I am using Divider() between few elements. This Divider is rendered as a very thin grey (or black?) line. I am guessing 1 point. How can I change the width of Divider()? 回答1: You can create any divider you wish, colors, width, content... As in below example. struct ExDivider: View { let color: Color = .gray let width: CGFloat = 2 var body: some View { Rectangle() .fill(color) .frame(height: width) .edgesIgnoringSafeArea(.horizontal) } } 回答2: For anyone

Can I add WidgetKit extensions to an app with target iOS < 14?

前提是你 提交于 2021-01-02 05:48:30
问题 I want to add a (WidgetKit-)widget to my iOS app. The app itself should keep a target of < 14. Obviously, the widget would be available only on those devices >= 14, but the app should run on all other devices as well. Is this possible? 回答1: Yes, you can as I develop the Widgets on an iOS13 Xcode project. You can see them on an iPhone that runs iOS14 and not on the iOS13 one. You just need to add @available(iOS14) in your code because you are using WidgetKit. But don't worry, Xcode will remind

Can I add WidgetKit extensions to an app with target iOS < 14?

邮差的信 提交于 2021-01-02 05:46:16
问题 I want to add a (WidgetKit-)widget to my iOS app. The app itself should keep a target of < 14. Obviously, the widget would be available only on those devices >= 14, but the app should run on all other devices as well. Is this possible? 回答1: Yes, you can as I develop the Widgets on an iOS13 Xcode project. You can see them on an iPhone that runs iOS14 and not on the iOS13 one. You just need to add @available(iOS14) in your code because you are using WidgetKit. But don't worry, Xcode will remind

How to set an Environment Object in preview

大城市里の小女人 提交于 2021-01-02 05:41:58
问题 My view needs an environment object which is set in the SceneDelegate by adding it to the window.rootViewController. How can I set an environment object to be used for the preview? 回答1: You add it using .environmentObject(_:) modifier: struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() .environmentObject(YourObject()) } } 回答2: This userData property gets its value automatically, as long as the environmentObject(_:) modifier has been applied to a

How to set an Environment Object in preview

只谈情不闲聊 提交于 2021-01-02 05:41:19
问题 My view needs an environment object which is set in the SceneDelegate by adding it to the window.rootViewController. How can I set an environment object to be used for the preview? 回答1: You add it using .environmentObject(_:) modifier: struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() .environmentObject(YourObject()) } } 回答2: This userData property gets its value automatically, as long as the environmentObject(_:) modifier has been applied to a

SwiftUI Index out of range in ForEach

怎甘沉沦 提交于 2021-01-02 03:58:48
问题 After hours of debugging I figured out the error is inside the foreach loop in MenuItemView in the folder ContentViews . The app crashes and the error is: Fatal error: Index out of range: file Swift/ContiguousArrayBuffer.swift, line 444 . Information: I have got an ObservableObject with an Array of Structs inside as data storage. The problem: The ForEach goes between 0 and the array count + 1. This is so I can have an extra item for adding new elements. In the ForEach is a check if the index

SwiftUI Index out of range in ForEach

让人想犯罪 __ 提交于 2021-01-02 03:58:32
问题 After hours of debugging I figured out the error is inside the foreach loop in MenuItemView in the folder ContentViews . The app crashes and the error is: Fatal error: Index out of range: file Swift/ContiguousArrayBuffer.swift, line 444 . Information: I have got an ObservableObject with an Array of Structs inside as data storage. The problem: The ForEach goes between 0 and the array count + 1. This is so I can have an extra item for adding new elements. In the ForEach is a check if the index