Post

Replies

Boosts

Views

Activity

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
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 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 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 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 volumeUUIDString missing
If coling the volume means, that the content is cloned as well, then that could be fine for my use case (well actually there might be edge cases where it would not). So let me explain why I want to do it:Essentially what I am trying to do (on an abstract level), is to write an application which catalogues files, which may or may not be stored on external drives. Some metadata of those files would be stored locally in an import step and also available if the external drive is not connected. If the user needs to access the original file, the application should be able to detect if the proper drive and thus the file (if not deleted, etc.) is available or not.On a not so abstract level: Think of cataloging photos from SD cards from the same camera. Using the SD cards basically as film rolls, meaning never overwriting them. If the original photo needs to be retrieved, the SD card may be plugged in, is automatically detected and the file can be retrieved.Not sure if my explanation is good enough, though. ;-)Thanks, Michael
Jun ’20
Reply to volumeUUIDString missing
Bookmarks! That was the hint I needed :-)So far testing looks good: Both the good and the problematic SD cards were identified correctly.Thanks for the help, Quinn! I'll make sure to have the proper coding in place, for cases when the approach with the bookmarks fails horribly.Cheers, Michael
Jun ’20