UPDATE:Seems to be simulator only.
Post
Replies
Boosts
Views
Activity
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
Hi,I did a little bit further testing with different simulators and on device:Simulator:iPhone 11 Pro -> it "jumps"iPhone 11 Pro Max -> everything is fineiPhone 11 -> everything is fineDevice:iPhone 11 -> it "jumps".Hmm, strange.Cheers, Michael
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")
}
}
}
}
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
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
}
}
}
@Claude31: There was one thing I needed to do before...Issue is logged as FB7693466.... hm it seems I can't close it right now. I always get an error. I will try again later.
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
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
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
Hi,
has anybody figured out in the meantime the why's and when's (James original questions)?
I am currently trying to develop a macOS app with SwiftUI's new app lifecycle and a document package as persistence and am really struggling to find out what the best approach here is...
Thanks!
(This should be a reply to the answer from mjcotr. But for some reason the reply does not seem to work as expected.)
Thank you, that looks exactly like what I was looking for. I haven't had heard about @NSApplicationDelegateAdaptor before.
I'll give it a try!
Thanks, Michael
I think I just ran into the a same issue: https://developer.apple.com/forums/thread/660976
So it seems the issue is still in Xcode 12 and Xcode 12.2 beta.
Now logged as FB8714689.
I have encountered pretty much the same issue: https://developer.apple.com/forums/thread/660976
Filed as: FB8714689