swiftui

Add EnvironmentObject in SwiftUI 2.0

陌路散爱 提交于 2020-12-15 06:06:09
问题 Since SwiftUI 2.0 does not have an AppDelegate and SceneDelegate anymore, where should EnvironmentObjects be set? This how it was done previously, where do i have to add them now? window.rootViewController = UIHostingController(rootView: ContentView() .environmentObject(settings)) 回答1: Try the following: @main struct TestApp: App { @StateObject var settings: Settings = ... // init here var body: some Scene { WindowGroup { ContentView() .environmentObject(settings) } } } 来源: https:/

Add EnvironmentObject in SwiftUI 2.0

拈花ヽ惹草 提交于 2020-12-15 06:05:33
问题 Since SwiftUI 2.0 does not have an AppDelegate and SceneDelegate anymore, where should EnvironmentObjects be set? This how it was done previously, where do i have to add them now? window.rootViewController = UIHostingController(rootView: ContentView() .environmentObject(settings)) 回答1: Try the following: @main struct TestApp: App { @StateObject var settings: Settings = ... // init here var body: some Scene { WindowGroup { ContentView() .environmentObject(settings) } } } 来源: https:/

Deleting CoreData Item which is also an @ObservedObject in DetailView causing App Crash in Swift 5

落爺英雄遲暮 提交于 2020-12-15 05:27:54
问题 i am currently working with SwiftUI and CoreData . Situation: I have a User Detail View with a Delete Button at the Bottom. When pressed, the Core Data Entry of the User is getting deleted and the App Navigation goes back to the Root Navigation View, which is a List of all Users. Problem: Every Time the Delete Button is clicked the App crashes with the following Error Message : *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[User timeCreated]:

Deleting CoreData Item which is also an @ObservedObject in DetailView causing App Crash in Swift 5

本小妞迷上赌 提交于 2020-12-15 05:26:16
问题 i am currently working with SwiftUI and CoreData . Situation: I have a User Detail View with a Delete Button at the Bottom. When pressed, the Core Data Entry of the User is getting deleted and the App Navigation goes back to the Root Navigation View, which is a List of all Users. Problem: Every Time the Delete Button is clicked the App crashes with the following Error Message : *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[User timeCreated]:

SwiftUI - How do I change a synchronous value using an asynchronous operation inside a List Cell

陌路散爱 提交于 2020-12-15 05:14:26
问题 I have this previous question properly answer. That case is of an image somewhere in the interface. I have another variation of the same problem but now the image is inside a List Cell. That image shows a padlock that must only show if a particular inapp purchase was not purchased, on SwiftUI. Something like Image(systemName: "lock.circle.fill") .renderingMode(.template) .foregroundColor(.white) .font(symbolFont) .opacity(wasPurchased(item: item)) But as far as I see wasPurchased must be a

SwiftUI - View disappears if animated

南楼画角 提交于 2020-12-15 02:05:08
问题 I am building a custom segmented control. This is the code that I have written. struct SegmentedControl: View { private var items: [String] = ["One", "Two", "Three"] @Namespace var animation:Namespace.ID @State var selected: String = "One" var body: some View { ScrollView(.horizontal) { HStack { ForEach(items, id: \.self) { item in Button(action: { withAnimation(.spring()){ self.selected = item } }) { Text(item) .font(Font.subheadline.weight(.medium)) .foregroundColor(selected == item ?

SwiftUI - View disappears if animated

杀马特。学长 韩版系。学妹 提交于 2020-12-15 02:03:17
问题 I am building a custom segmented control. This is the code that I have written. struct SegmentedControl: View { private var items: [String] = ["One", "Two", "Three"] @Namespace var animation:Namespace.ID @State var selected: String = "One" var body: some View { ScrollView(.horizontal) { HStack { ForEach(items, id: \.self) { item in Button(action: { withAnimation(.spring()){ self.selected = item } }) { Text(item) .font(Font.subheadline.weight(.medium)) .foregroundColor(selected == item ?

SwiftUI - View disappears if animated

六月ゝ 毕业季﹏ 提交于 2020-12-15 02:01:35
问题 I am building a custom segmented control. This is the code that I have written. struct SegmentedControl: View { private var items: [String] = ["One", "Two", "Three"] @Namespace var animation:Namespace.ID @State var selected: String = "One" var body: some View { ScrollView(.horizontal) { HStack { ForEach(items, id: \.self) { item in Button(action: { withAnimation(.spring()){ self.selected = item } }) { Text(item) .font(Font.subheadline.weight(.medium)) .foregroundColor(selected == item ?

SwiftUI textfield color

拜拜、爱过 提交于 2020-12-13 19:01:27
问题 any idea how to change the color of the textfield placeholder like the attached picture? I can't find the way to color the text "email" in white, it always stay in grey. i want to make it same like the picture. thanks a lot for the help SecureField(String("Password"), text: $pass).padding(.all).border(Color.white).cornerRadius(3.0).padding(.horizontal) 回答1: Find below a demo of some possible approach. Also might worth considering representable around UITextField as it is much more

SwiftUI iOS14 GeometryReader Invalid frame dimension

余生长醉 提交于 2020-12-13 18:56:17
问题 My GeometryReader was working fine in iOS13 but now in iOS14 i get a thread issue. "Invalid frame dimension (negative or non-finite)." I printed the size that the reader should give back and it looked fine. The app is still basically working, but looks a bit weird, because there is some padding introduced. Does anyone have any ideas how to tackle this? 来源: https://stackoverflow.com/questions/64027041/swiftui-ios14-geometryreader-invalid-frame-dimension