Swiftpack.co -  theoriginalbit/PreviewView as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
theoriginalbit/PreviewView
Make use of SwiftUI Previews for UIKit!
.package(url: "https://github.com/theoriginalbit/PreviewView.git", from: "1.0.0")

PreviewView

Make use of SwiftUI previews for your UIKit controllers!

It's as simple as:

struct YourViewController_Previews: PreviewProvider {
    static var previews: some View {
        PreviewView(for: YourViewController())
            .edgesIgnoringSafeArea(.all)
            .previewDevice(PreviewDevice(rawValue: "iPhone 11"))
    }
}

If your view controller is meant to be displayed in a UINavigationController just add .wrapInNavigationController()

struct YourViewController_Previews: PreviewProvider {
    static var previews: some View {
        PreviewView(for: YourViewController())
            .wrapInNavigationController()
            .edgesIgnoringSafeArea(.all)
            .previewDevice(PreviewDevice(rawValue: "iPhone 11"))
    }
}

The .wrapInNavigationController() function accepts a single parameter prefersLargeTitles which allows you to also configure the navigation controller's navigationBar.prefersLargeTitles property; by default it will be set to false.

PRO TIP: Did you know that you can easily create multiple previews with a simple ForEach loop?

struct YourViewController_Previews: PreviewProvider {
    static var previews: some View {
        ForEach(["iPhone 11", "iPhone 8", "iPhone SE (1st generation)"], id: \.self) { deviceName in
            PreviewView(for: YourViewController())
                .edgesIgnoringSafeArea(.all)
                .previewDevice(PreviewDevice(rawValue: deviceName))
                .previewDisplayName(deviceName)
        }
    }
}

GitHub

link
Stars: 2
Last commit: 3 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API