Safe and fast access to SwiftUI PreviewDevice

Overview

SafePreviewDevice

Swift: 5.1 Version: 0.1.0 Platforms: iOS – tvOS – watchOS - macOS License: MIT
SwiftPM: Compatible CocoaPods: Compatible

Motivation

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 is looking for an easy way to select their preview device or they just don't remember every iOS 13 device name (like me 😀 )

System Requirements

Supported platforms are iOS (13.0), tvOS (13.0), watchOS (6.0) and macOS (10.15) and of course Xcode 11.

Installation

SafePreviewDevice can be installed via Swift Package Manager.

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

CocoaPods

Add the following entry to your Podfile:

pod 'SafePreviewDevice'

Then run pod install.

Usage

Simply import this framework in your SwiftUI file and add one of this View modifier to your preview:

Display a preview device

.previewDevice(.iPhone7)

This modifier will change the displayed device in the Xcode SwiftUI preview.

Change the preview device name

.previewDeviceName(.iPhone7)

This modifier will change the displayed device name in the Xcode SwiftUI preview.

What's new 🚀

Display a named preview device

.previewNamedDevice(.iPhone7)

This modifier is the union between the first APIs. It will change the displayed device in the Xcode SwiftUI preview setting also the device name.

Display a preview device applying the color scheme

.previewDevice(.iPhone7, withColorScheme: .dark)

This modifier will change the displayed device in the Xcode SwiftUI preview. It also applies the selected color scheme.

Display a named preview device applying the color scheme

.previewNamedDevice(.iPhone7, withColorScheme: .dark)

This modifier will change the displayed named device in the Xcode SwiftUI preview. It also applies the selected color scheme.

Display a group of named preview device applying a list of color scheme

.previewDevices([.iPhone7, .iPhoneSE, .iPhoneX], withColorScheme: [.dark, .light])

This modifier provides an inline alternative to

Group {
    MyView().previewDevice(.iPhone7, withColorScheme: .dark)
    MyView().previewDevice(.iPhone7, withColorScheme: .light)
    MyView().previewDevice(.iPhoneSE, withColorScheme: .dark)
    MyView().previewDevice(.iPhoneSE, withColorScheme: .light)
    MyView().previewDevice(.iPhoneX, withColorScheme: .dark)
    MyView().previewDevice(.iPhoneX, withColorScheme: .light)
}

Contributing

  • 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.

Acknowledgements

Made with ❤️ in Milan by Antonino Musolino.

You might also like...
Customize and resize sheets in SwiftUI with SheeKit. Utilise the power of `UISheetPresentationController` and other UIKit features.
Customize and resize sheets in SwiftUI with SheeKit. Utilise the power of `UISheetPresentationController` and other UIKit features.

SheeKit Customize and resize sheets in SwiftUI with SheeKit. Utilise the power of UISheetPresentationController and other UIKit features. Overview She

🟣 Verge is a very tunable state-management engine on iOS App (UIKit / SwiftUI) and built-in ORM.
🟣 Verge is a very tunable state-management engine on iOS App (UIKit / SwiftUI) and built-in ORM.

Verge is giving the power of state-management in muukii/Brightroom v2 development! Verge.swift 📍 An effective state management architecture for iOS -

Pigeon is a SwiftUI and UIKit library that relies on Combine to deal with asynchronous data.

Pigeon 🐦 Introduction Pigeon is a SwiftUI and UIKit library that relies on Combine to deal with asynchronous data. It is heavily inspired by React Qu

Recreating a fully functional version of iOS 4 in SwiftUI.
Recreating a fully functional version of iOS 4 in SwiftUI.

Updates: Version 1.0 is currently available 🎉 While I work on fixing an issue in Xcode 12.5+ with LazyVGrid, I recommend you build using Xcode 12.4 a

I needed to detect idle mode on a SwiftUI app for a kiosk, so I did it.

Inactivity I needed to detect idle mode on a SwiftUI app for a kiosk, so I did it. Usage Important: You must set the Principal class of your app to In

SnippetsLibrary - Code snippets library for SwiftUI Devs.
SnippetsLibrary - Code snippets library for SwiftUI Devs.

SnippetsLibrary is a helpful tool for SwiftUI developers to help with their daily coding life. SnippetsLibrary contains all the needed code snippets for you to view, edit, or add more and more. This will make your daily work easier and faster.

*Random Smooth Cloudy* Noise for SwiftUI
*Random Smooth Cloudy* Noise for SwiftUI

Noise Generate random smooth cloudy noise. Install Swift Package .

Observe objects in SwiftUI Views which may be nil

ObservedOptionalObject Rationale SwiftUIs @ObservedObject requires that the observed object actually exists. In some cases it's convenient to observe

SwiftUI library to create fully customizable input stepper.
SwiftUI library to create fully customizable input stepper.

SwiftUI-InputStepper Swift package for creating numerical input stepper. An example of input stepper created with this library It supports long press

Releases(0.3.0)
  • 0.3.0(Jan 17, 2022)

  • 0.2.0(May 26, 2020)

    [0.2.0] The Improved Release 🚀

    Added

    • previewNamedDevice(_:): This modifier is the union between the first APIs. It will change the displayed device in the Xcode SwiftUI preview setting also the device name.

    • previewDevice(_:, withColorScheme:): This modifier will change the displayed device in the Xcode SwiftUI preview. It also applies the selected color scheme.

    • previewNamedDevice(_:, withColorScheme: ): This modifier will change the displayed named device in the Xcode SwiftUI preview. It also applies the selected color scheme.

    • previewDevices(_:, withColorScheme:): This modifier provides an inline alternative to Group

    Changed

    • None

    Fixed

    • None
    Source code(tar.gz)
    Source code(zip)
  • 0.1.0(Apr 30, 2020)

    [0.1.0] Hello Release 👋

    Added

    • Two View extensions: previewDevice(_ device: Devices) previewDeviceName(_ device: Devices) that will simplify your PreviewDevice choice.

    Changed

    • None

    Fixed

    • None
    Source code(tar.gz)
    Source code(zip)
Owner
Antonino Francesco Musolino
Senior iOS Engineer @ Kering
Antonino Francesco Musolino
🚀Comprehensive Redux library for SwiftUI, ensures State consistency across Stores with type-safe pub/sub pattern.

??Comprehensive Redux library for SwiftUI, ensures State consistency across Stores with type-safe pub/sub pattern.

Cheng Zhang 18 Mar 9, 2022
💻 A fast and flexible O(n) difference algorithm framework for Swift collection.

A fast and flexible O(n) difference algorithm framework for Swift collection. The algorithm is optimized based on the Paul Heckel's algorithm. Made wi

Ryo Aoyama 3.3k Jan 4, 2023
🦀Amazingly incredible extraordinary lightning fast diffing in Swift

DeepDiff ❤️ Support my apps ❤️ Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcut man

Khoa 2k Dec 29, 2022
FastLayout - A UIKit or AppKit package for fast UI design

FastLayout FastLayout is a UIKit or AppKit package for fast UI design. Layout Ex

null 1 Feb 19, 2022
A declarative, thread safe, and reentrant way to define code that should only execute at most once over the lifetime of an object.

SwiftRunOnce SwiftRunOnce allows a developer to mark a block of logic as "one-time" code – code that will execute at most once over the lifetime of an

Thumbtack 8 Aug 17, 2022
Type-Safe Associated Objects in Swift

Type-Safe Associated Objects in Swift TSAO is an implementation of type-safe associated objects in Swift. Objective-C associated objects are useful, b

Lily Ballard 135 Dec 21, 2022
Swift package for accessing SF Symbols in a type safe manner.

Swift Package Information Code Coverage Swift package for accessing SF Symbols in a type safe manner. Features ?? Contains all SF Symbols - 1.0, 2.0,

null 6 Dec 7, 2021
OTAtomics - Multi-platform Swift thread-safe atomics library

OTAtomics Multi-platform Swift thread-safe atomics library. The library has full

Steffan Andrews 2 Jul 8, 2022
MediaType is a library that can be used to create Media Types in a type-safe manner.

This is a general purpose Swift library for a concept of typed treatment for Media Types. We use this library on clients and servers to speak the same dialect and to enjoy all the comfort strong types provide over raw strings.

21Gram Consulting 79 Jul 19, 2022
Unit-Converter-SwiftUI - A simple Unit Converter iOS app built in the process of learning SwiftUI

SwiftUI-Unit-Converter A simple Unit Converter iOS app built in the process of l

Ishaan Bedi 2 Jul 13, 2022