At WWDC 2019, Apple announced SwiftUI a new library for building UI in a simple and fast way.
Xcode’s SwiftUI preview lets us show our application design in multiple screen sizes at the same time using the .previewDevice()
modifier. Currently, this needs to be provided with the exact name of the device you want to test: e.g. “iPhone XS Max”.
.previewDevice(PreviewDevice(rawValue: "iPhone XS Max"))
or even better
.previewDevice(.iPhone7)
This framework comes to rescue for everyone that are looking for an easy way to select their preview device or they just doesn't remember every iOS 13 device name (like me 😀)
Supported platforms are iOS (13.0)
, tvOS (13.0)
, watchOS (6.0)
and macOS (10.15)
and of course Xcode 11
.
SafePreviewDevice
can be installed via Swift Package Manager.
To integrate using Apple's Swift package manager, add the following as a dependency to your Package.swift
:
.package(url: "https://github.com/posix88/SafePreviewDevice.git", .upToNextMajor(from: "0.1.0"))
and run swift package update
.
Otherwise you can simply go to File -> Swift Packages -> Add Package Dependency and paste the repo's url: https://github.com/posix88/SafePreviewDevice
Simply import this framework in your SwiftUI
file and add one of this View
modifier
.previewDevice(.iPhone7)
This modifier will change the device in Xcode SwiftUI preview.
.previewDeviceName(.iPhone7)
This modifier will change the device name in Xcode SwiftUI preview.
- If you need help or you'd like to ask a general question, open an issue.
- If you found a bug, open an issue.
- If you have a feature request, open an issue.
- If you want to contribute, submit a pull request.
Made with ❤️ in Milan by Antonino Musolino.