跳转至
Enumeration

PreviewPlatform

The operating system on which to run the preview.

Declaration

enum PreviewPlatform

Overview

By default, Xcode can infer the platform for a preview based on the target of the current file. However, you can also use this enumeration along with the platform property to change the way a view is displayed in a preview.

Author's note: I tried to use this to change the preview platform, but I couldn't get anything to work. It seems right now that the only way to change your preview device is by actually changing your build target.

This enumeration has 4 different cases:

  1. iOS
  2. macOS
  3. tvOS
  4. watchOS

In the following example, we change the preview platform to macOS.

struct ContentView: View {
    var body: some View {
        Text("I should be in a Mac 🖥")
    }
}

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

    static var platform: PreviewPlatform? { .macOS }
}

Availability

iOS 13.0+

macOS 10.15+

tvOS 13.0+

watchOS 6.0+

Topics


Case

iOS The iOS preview platform.

macOS The macOS preview platform.

tvOS The tvOS preview platform.

watchOS The watchOS preview platform.


Instance Property

hashValue The hash value.


Instance Method

hash(into:) Hashes the essential components of this value by feeding them into the given hasher.


Type Method

==(a:b:) Returns a Boolean value indicating whether two values are equal.