User location undefined in SwiftUI Preview

In the wwdc2023-10043 session, the instructor adds a MapUserLocationButton towards the end, which seems to work fine in the SwiftUI Preview for him.

However, when I follow this tutorial and add the very same button, I get a never-ending spinning wheel upon clicking it in SwiftUI Preview. I guess that the SwiftUI Preview cannot get a user location.

I searched in various places whether I could set the user location, as possible in the simulator, but to no avail.

In the Debug menu, there is a Simulate Location submenu, but it totally deactivated (greyed out).

Does anyone know how to allow SwiftUI Preview to get an actual user location, i.e., either the one from my Mac or one that I could provide to the SwiftUI Preview simulator?

Hi,

You are hitting a known issue that should be fixed in the latest Xcode 15 beta. Could you try updating and see if it works? If not, then the next steps would be to file a feedback and report back here with the ID:

Steps to generate helpful diagnostics:

  1. Download and install the logging profile on all devices involved. Instructions and profiles are available here: https://developer.apple.com/bug-reporting/profiles-and-logs/?name=swift
  2. Reproduce the issue
  3. Click the "Diagnostics" button in the error banner in Previews' Canvas area (or if the banner is missing you can use the menu: Editor > Canvas > Diagnostics)
  4. In the sheet that appears, click "Generate Report" in the bottom left of the sheet
  5. Attach (or make from the folder) the resulting zip file to the bug (will be named something like previews-diagnostics-0123456789.zip)
  6. Generate the sysdiagnose(s) and attach those too

I had this same issue and it was because I hadn't requested location permissions in info.plist for my application. Once I added that permission and ran a build of my app, the SwiftUI previews allowed simulate location.

User location undefined in SwiftUI Preview
 
 
Q