Post

Replies

Boosts

Views

Activity

Reply to volumeUUIDString missing
Thank you, Quinn, for the quick clarification.Do you have any suggestion what else (other than writing a "dot" file withe a UUID) could be used to uniquely identify a volume? Or do you think that writing a file with a UUID is my best bet?Thanks again, Michael
Jun ’20
Reply to Update issue with ScrollView + ForEach
To answer to myself with a workaround (in case anybody has the same issue and is looking for one), please see below:Still I think the original code should work, right?It seems that a ScrollView can't can't be initially empty:struct ContentView: View { @ObservedObject var user = UserViewModel() var body: some View { Group { if user.users.isEmpty { EmptyView() } else { ScrollView { // comment scrollview out and it works ForEach(user.users, id: \.self) { user in Text("\(user.name)") } } } } .onAppear { self.user.get() // to simulate model update } } }
May ’20
Reply to NavigationLink and the linked Views
Hi DMG,thanks for the reply. That would definitely work for the concrete code example I gave, but unfortunately not in my real use case, where I need to inject that value from outside of NextView.(The real scenario is passing a child NSManagedObjectContext to "NextView" right before the navigation takes place.)Thanks again for the reply, Michael
Mar ’20
Reply to Multiple levels of Bindings don't update properly
Hi,I am sure I can't explain it in a good way, but I think the issue is, that you are passing on the @Binding and not the the object itself (as you do in the ContentView) as the single source of truth. I think the best way is probably to pass on the model object (MyObject) itself. See the modified coding below. And yes, I think more in depth documentation about SwiftUI and the concepts would be helpful here ;-).HTH, Michaelclass MyObject: ObservableObject { @Published var number: Int = 1 } struct ContentView: View { @ObservedObject var myObject: MyObject var body: some View { NavigationView { VStack { Text("number: \(myObject.number)") NavigationLink(destination: PushedView(obj: myObject, pushLevel: 1)) { Text("Push a View") } } } } } struct PushedView: View { @ObservedObject var obj: MyObject let pushLevel: Int func incrementIt() { obj.number += 1 } var body: some View { VStack { Text("Pushed View (level \(pushLevel))") Text("number (via binding): \(obj.number)") Button(action: self.incrementIt) { Text("Increment number") } NavigationLink(destination: PushedView(obj: obj, pushLevel: pushLevel + 1)) { Text("Push a View") } } } }
Mar ’20
Reply to How to track down "precondition failure: attribute failed to set an initial value: ???" errors?
Hi Claude,thanks the links helped to solve(?) workaround(?) the issue. I'll add a minimalist example below for reference, if somebody else stumbles across this (or similar) issues. Seems like a bug to me... (FB7581633)import SwiftUI struct ContentView: View { var body: some View { NavigationView { List { NavigationLink(destination: Detail()) { Text("Tap here") } } } .navigationViewStyle(StackNavigationViewStyle()) } } struct Detail: View { var body: some View { NavigationView { // comment out to let the app crash when navigating in portrait orientation GeometryReader { geo in if geo.size.height > geo.size.width { self.portrait .frame(width: geo.size.width, height: geo.size.height) } else { self.landscape .frame(width: geo.size.width, height: geo.size.height) } } } .navigationBarTitle(LocalizedStringKey("Edit entry")) } var portrait: some View { VStack { // won't crash if this was an HStack, even if geometry reader is not wrapped in an NavigationView Text("This is portrait. Crashes if Geometry reader is not wrapped in a NavigationView.") } } var landscape: some View { HStack { Text("This is landscape. Works.") } } }Cheers, Michael
Feb ’20