3

How can I render the Xcode Preview to a iMac device when I develop a macOS app there is no real device in

   struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
           ContentView()
    }
   }

All I see is the code I write but I would like to see the whole device before I even write a line code Apple is so inconsistent...

I Run Xcode on MacBook and iMac Pro and would like to see both devices in preview

Any help is highly valued!

2
  • Have you experimented with the previewDevice modifier? Commented Feb 1, 2020 at 0:38
  • 1
    Hey John thanks I tried them but it seems Mac is not really supported I will try it on iMac maybe the screen is just to small on a MacBook. Thanks for your help Commented Feb 1, 2020 at 13:31

1 Answer 1

4

Try the following:

struct ContentView_Previews: PreviewProvider {
   static var previews: some View {
       ContentView()
           .previewDevice(PreviewDevice(rawValue: "Mac"))
   }
}

The list of devices you can specify for that rawValue (as of right now) is:

  • "Mac"
  • "iPhone 7"
  • "iPhone 7 Plus"
  • "iPhone 8"
  • "iPhone 8 Plus"
  • "iPhone SE"
  • "iPhone X"
  • "iPhone Xs"
  • "iPhone Xs Max"
  • "iPhone Xr"
  • "iPad mini 4"
  • "iPad Air 2"
  • "iPad Pro (9.7-inch)"
  • "iPad Pro (12.9-inch)"
  • "iPad (5th generation)"
  • "iPad Pro (12.9-inch) (2nd generation)"
  • "iPad Pro (10.5-inch)"
  • "iPad (6th generation)"
  • "iPad Pro (11-inch)"
  • "iPad Pro (12.9-inch) (3rd generation)"
  • "iPad mini (5th generation)"
  • "iPad Air (3rd generation)"
  • "Apple TV"
  • "Apple TV 4K"
  • "Apple TV 4K (at 1080p)"
  • "Apple Watch Series 2 - 38mm"
  • "Apple Watch Series 2 - 42mm"
  • "Apple Watch Series 3 - 38mm"
  • "Apple Watch Series 3 - 42mm"
  • "Apple Watch Series 4 - 40mm"
  • "Apple Watch Series 4 - 44mm"

Apple's documentation is a little lackluster on this one, but some of the info for this can be found at this link: https://developer.apple.com/documentation/swiftui/previewdevice

I paid for a macOS App that does a phenomenal job of sifting through the SwiftUI documentation (waaaaay better than what Apple put out). It's a little pricey, but if you're interested, it can be found at: https://apps.apple.com/us/app/a-companion-for-swiftui/id1485436674?mt=12

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.