XCode Simulator Device Class Size Problem

I'm having trouble with XCode Simulator and device rotation using SwiftUI app. (Simulator Version 14.3.1 (994) SimulatorKit 629 CoreSimulator 885.2)

The horizontalSizeClass/verticalSizeClass as reported by simulator does not match the sizes given in https://developer.apple.com/design/human-interface-guidelines/layout when rotating the device.

It is correct on initial start, but on first device rotation (say e.g. portrait to landscape orientation) the values remain the same, despite monitoring with .onChange suggesting that they have changed! Then it appears to lag one device rotation behind the actual orientation for subsequent rotations. Such that on second device rotation (say landscape back to portrait) the values change to those associated with landscape instead of portrait - and so on for all subsequent rotations.

It's a particular issue with "large" iPhones when simulator gives width = .compact and height = .regular in landscape orentation when it should be the other way round!

Any insights from anyone as what is going on? Is it a bug or am I doing something wrong? Thanks

You may be encountering a bug or an unexpected behavior in Xcode Simulator. However, without examining your code directly, it's difficult to determine the exact cause of the issue. Here are a few things you can check and potential solutions to try:

  1. Ensure that you're correctly using the size classes in your SwiftUI code. Make sure you are accessing the size classes from the environment variables and updating your UI accordingly. For example, you can access the size classes using @Environment(\.horizontalSizeClass) and @Environment(\.verticalSizeClass).

  2. Verify that you are using the correct size class values when adapting your UI to different orientations. The values reported by the simulator may not match the sizes mentioned in the Human Interface Guidelines you referenced, as those guidelines may not be updated for the latest simulator versions. You can use the simulator to test and determine the correct behavior for different device orientations.

  3. Consider updating Xcode to the latest version available. The issue you're experiencing may have been addressed in a newer release. Checking for updates and installing them may help resolve the problem.

  4. If you suspect it may be a bug in Xcode, you can try running your app on a physical device to see if the behavior persists. Testing on an actual device can help determine if the issue is specific to the simulator or if it's a broader problem.

Remember to always keep your development environment up to date, as new updates may include bug fixes and improvements that can resolve issues you're experiencing.

Thanks for your help.

  1. Yes that's what I'm doing
  2. Maybe that is the issue?
  3. Xcode up to date (but not using 15 beta - dont want to get into beta besting xcode!)
  4. Will give that a try and see what happens.

Thanks again

XCode Simulator Device Class Size Problem
 
 
Q