0

I have solved the problem but I would like to understand why it occurs

Using xCode Version 14.0.1 (14A400)

For iPhone Pro 14 Ios16 simulation with the following ContentView coding

@EnvironmentObject var objectPickVM: ObjectPickViewModel

...                NavigationLink(destination:
                                PickSavedObjectView()
//                                .environmentObject(objectPickVM)
//                                .environmentObject(coreDataVM)
                               , isActive: self.$isActive ) {
                    Text("Saved equipment")
                        .font(isActive ? .headline:.body)
                }

compiles and runs without any problem.

However for an iPad mini (6th generation) ios16 simulation unless I activate

                                .environmentObject(objectPickVM)
                                .environmentObject(coreDataVM)

the compiler crashes with "Fatal error: No ObservableObject of type ObjectPickViewModel found. A View.environmentObject(_:) for ObjectPickViewModel may be missing as an ancestor of this view."

As a novice coder I may well have made an error in my implementation of @StateObject, @Published and .environmentObject(), but I cannot understand why the iPhone does not require the added coding but the iPad simulation does. There is no device type related code in my programme.

Is there a distinction between how iPhone and iPad implement NavigationLink?

Could someone direct me to any discussion of this as I attempted but could not find it.

  • That thread provided the solution and did answer my original problem. However, I cannot understand why the iPhone simulation worked when the iPad simulation did not work when the code was identical - no conditional statements based on device type - for both simulations. – xScotland99 May 04 '23 at 16:56
  • Are you using NavigationView? If so, on iPhone it is a Stack and on iPad it is a Double Column/Split. – lorem ipsum May 04 '23 at 17:37
  • Yes I am using NavigationView. So there is a difference between the iPhone and iPad. I can now read up on the the difference between the Stack and the Double Column/Split. Thank you. – xScotland99 May 04 '23 at 18:59
  • Yes there is Stack vs Double Column or Master/Detail. It is evident in posts like [this](https://stackoverflow.com/questions/70482156/swift-why-does-the-ipad-mac-app-version-look-weird/70482643#70482643) on SO. – lorem ipsum May 04 '23 at 19:00

0 Answers0