Make UIKit project enable preview feature of SwiftUI

DGPreview

Make UIKit project enable preview feature of SwiftUI

Requirements

  • iOS 13 +
  • Swift 5 +
  • Xcode 13 +

Installaction

SPM

File > Add Packages > https://github.com/donggyushin/DGPreview

CocoaPod

pod 'DGPreview', :git => 'https://github.com/donggyushin/DGPreview'

Usage

UIView

import SwiftUI
import DGPreview

struct MyButtonPreview: PreviewProvider {
    static var previews: some View {
        DGPreview {
            return MyButton()
        }.previewLayout(.sizeThatFits)
    }
}

UIViewController

import SwiftUI
import DGPreview

struct ViewControllerPreview: PreviewProvider {
    static var previews: some View {
        ViewController().showDGPreview(.iPhone13Pro)
    }
}

GitHub

View Github