├── SwiftPreview.xctemplate ├── TemplateIcon-1016.png ├── TemplateIcon-1016@2x.png ├── UICollectionViewCellSwift │ └── ___FILEBASENAME___.swift ├── UICollectionReusableViewSwift │ └── ___FILEBASENAME___.swift ├── UICollectionViewCellXIBSwift │ ├── ___FILEBASENAME___.swift │ └── ___FILEBASENAME___.xib ├── UICollectionReusableViewXIBSwift │ ├── ___FILEBASENAME___.swift │ └── ___FILEBASENAME___.xib ├── UIViewSwift │ └── ___FILEBASENAME___.swift ├── UITableViewCellSwift │ └── ___FILEBASENAME___.swift ├── UITableViewCellXIBSwift │ ├── ___FILEBASENAME___.swift │ └── ___FILEBASENAME___.xib └── TemplateInfo.plist ├── .gitignore ├── SwiftPreviewController.xctemplate ├── TemplateIcon-1016.png ├── TemplateIcon-1016@2x.png ├── UIViewControllerSwift │ └── ___FILEBASENAME___.swift ├── UIViewControllerXIBSwift │ ├── ___FILEBASENAME___.swift │ └── ___FILEBASENAME___.xib ├── UITableViewControllerSwift │ └── ___FILEBASENAME___.swift ├── UITableViewControllerXIBSwift │ ├── ___FILEBASENAME___.swift │ └── ___FILEBASENAME___.xib ├── UICollectionViewControllerXIBSwift │ ├── ___FILEBASENAME___.swift │ └── ___FILEBASENAME___.xib ├── UICollectionViewControllerSwift │ └── ___FILEBASENAME___.swift └── TemplateInfo.plist ├── Templates ├── SwiftPreview.xctemplate │ ├── TemplateIcon-1016.png │ ├── TemplateIcon-1016@2x.png │ ├── UICollectionViewCellSwift │ │ └── ___FILEBASENAME___.swift │ ├── UICollectionReusableViewSwift │ │ └── ___FILEBASENAME___.swift │ ├── UICollectionViewCellXIBSwift │ │ ├── ___FILEBASENAME___.swift │ │ └── ___FILEBASENAME___.xib │ ├── UICollectionReusableViewXIBSwift │ │ ├── ___FILEBASENAME___.swift │ │ └── ___FILEBASENAME___.xib │ ├── UIViewSwift │ │ └── ___FILEBASENAME___.swift │ ├── UITableViewCellSwift │ │ └── ___FILEBASENAME___.swift │ ├── UITableViewCellXIBSwift │ │ ├── ___FILEBASENAME___.swift │ │ └── ___FILEBASENAME___.xib │ └── TemplateInfo.plist └── SwiftPreviewController.xctemplate │ ├── TemplateIcon-1016.png │ ├── TemplateIcon-1016@2x.png │ ├── UIViewControllerSwift │ └── ___FILEBASENAME___.swift │ ├── UIViewControllerXIBSwift │ ├── ___FILEBASENAME___.swift │ └── ___FILEBASENAME___.xib │ ├── UITableViewControllerSwift │ └── ___FILEBASENAME___.swift │ ├── UITableViewControllerXIBSwift │ ├── ___FILEBASENAME___.swift │ └── ___FILEBASENAME___.xib │ ├── UICollectionViewControllerXIBSwift │ ├── ___FILEBASENAME___.swift │ └── ___FILEBASENAME___.xib │ ├── UICollectionViewControllerSwift │ └── ___FILEBASENAME___.swift │ └── TemplateInfo.plist ├── SwiftPreview.podspec ├── Package.swift ├── LICENSE ├── Tests └── SwiftPreviewTests │ ├── TestDoubles │ ├── DummyView.swift │ └── DummyViewController.swift │ ├── UIViewPreviewTests.swift │ └── UIViewControllerPreviewTests.swift ├── README.md ├── Sources └── SwiftPreview │ ├── UIViewPreview.swift │ └── UIViewControllerPreview.swift └── install.sh /SwiftPreview.xctemplate/TemplateIcon-1016.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heoblitz/SwiftPreview/HEAD/SwiftPreview.xctemplate/TemplateIcon-1016.png -------------------------------------------------------------------------------- /SwiftPreview.xctemplate/TemplateIcon-1016@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heoblitz/SwiftPreview/HEAD/SwiftPreview.xctemplate/TemplateIcon-1016@2x.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /.build 3 | /Packages 4 | /*.xcodeproj 5 | xcuserdata/ 6 | DerivedData/ 7 | .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata 8 | -------------------------------------------------------------------------------- /SwiftPreviewController.xctemplate/TemplateIcon-1016.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heoblitz/SwiftPreview/HEAD/SwiftPreviewController.xctemplate/TemplateIcon-1016.png -------------------------------------------------------------------------------- /Templates/SwiftPreview.xctemplate/TemplateIcon-1016.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heoblitz/SwiftPreview/HEAD/Templates/SwiftPreview.xctemplate/TemplateIcon-1016.png -------------------------------------------------------------------------------- /SwiftPreviewController.xctemplate/TemplateIcon-1016@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heoblitz/SwiftPreview/HEAD/SwiftPreviewController.xctemplate/TemplateIcon-1016@2x.png -------------------------------------------------------------------------------- /Templates/SwiftPreview.xctemplate/TemplateIcon-1016@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heoblitz/SwiftPreview/HEAD/Templates/SwiftPreview.xctemplate/TemplateIcon-1016@2x.png -------------------------------------------------------------------------------- /Templates/SwiftPreviewController.xctemplate/TemplateIcon-1016.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heoblitz/SwiftPreview/HEAD/Templates/SwiftPreviewController.xctemplate/TemplateIcon-1016.png -------------------------------------------------------------------------------- /Templates/SwiftPreviewController.xctemplate/TemplateIcon-1016@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/heoblitz/SwiftPreview/HEAD/Templates/SwiftPreviewController.xctemplate/TemplateIcon-1016@2x.png -------------------------------------------------------------------------------- /SwiftPreview.xctemplate/UICollectionViewCellSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 6 | 7 | } 8 | 9 | #if canImport(SwiftUI) && DEBUG 10 | import SwiftUI 11 | import SwiftPreview 12 | 13 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 14 | static var previews: some View { 15 | UIViewPreview { 16 | ___FILEBASENAMEASIDENTIFIER___() 17 | } 18 | } 19 | } 20 | #endif -------------------------------------------------------------------------------- /SwiftPreview.xctemplate/UICollectionReusableViewSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 6 | 7 | } 8 | 9 | #if canImport(SwiftUI) && DEBUG 10 | import SwiftUI 11 | import SwiftPreview 12 | 13 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 14 | static var previews: some View { 15 | UIViewPreview { 16 | ___FILEBASENAMEASIDENTIFIER___() 17 | } 18 | } 19 | } 20 | #endif -------------------------------------------------------------------------------- /Templates/SwiftPreview.xctemplate/UICollectionViewCellSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 6 | 7 | } 8 | 9 | #if canImport(SwiftUI) && DEBUG 10 | import SwiftUI 11 | import SwiftPreview 12 | 13 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 14 | static var previews: some View { 15 | UIViewPreview { 16 | ___FILEBASENAMEASIDENTIFIER___() 17 | } 18 | } 19 | } 20 | #endif -------------------------------------------------------------------------------- /Templates/SwiftPreview.xctemplate/UICollectionReusableViewSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 6 | 7 | } 8 | 9 | #if canImport(SwiftUI) && DEBUG 10 | import SwiftUI 11 | import SwiftPreview 12 | 13 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 14 | static var previews: some View { 15 | UIViewPreview { 16 | ___FILEBASENAMEASIDENTIFIER___() 17 | } 18 | } 19 | } 20 | #endif -------------------------------------------------------------------------------- /SwiftPreviewController.xctemplate/UIViewControllerSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 6 | 7 | override func viewDidLoad() { 8 | super.viewDidLoad() 9 | } 10 | } 11 | 12 | #if canImport(SwiftUI) && DEBUG 13 | import SwiftUI 14 | import SwiftPreview 15 | 16 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 17 | static var previews: some View { 18 | UIViewControllerPreview { 19 | ___FILEBASENAMEASIDENTIFIER___() 20 | } 21 | } 22 | } 23 | #endif -------------------------------------------------------------------------------- /SwiftPreviewController.xctemplate/UIViewControllerXIBSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 6 | 7 | override func viewDidLoad() { 8 | super.viewDidLoad() 9 | } 10 | } 11 | 12 | #if canImport(SwiftUI) && DEBUG 13 | import SwiftUI 14 | import SwiftPreview 15 | 16 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 17 | static var previews: some View { 18 | UIViewControllerPreview { 19 | ___FILEBASENAMEASIDENTIFIER___() 20 | } 21 | } 22 | } 23 | #endif -------------------------------------------------------------------------------- /Templates/SwiftPreviewController.xctemplate/UIViewControllerSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 6 | 7 | override func viewDidLoad() { 8 | super.viewDidLoad() 9 | } 10 | } 11 | 12 | #if canImport(SwiftUI) && DEBUG 13 | import SwiftUI 14 | import SwiftPreview 15 | 16 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 17 | static var previews: some View { 18 | UIViewControllerPreview { 19 | ___FILEBASENAMEASIDENTIFIER___() 20 | } 21 | } 22 | } 23 | #endif -------------------------------------------------------------------------------- /Templates/SwiftPreviewController.xctemplate/UIViewControllerXIBSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 6 | 7 | override func viewDidLoad() { 8 | super.viewDidLoad() 9 | } 10 | } 11 | 12 | #if canImport(SwiftUI) && DEBUG 13 | import SwiftUI 14 | import SwiftPreview 15 | 16 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 17 | static var previews: some View { 18 | UIViewControllerPreview { 19 | ___FILEBASENAMEASIDENTIFIER___() 20 | } 21 | } 22 | } 23 | #endif -------------------------------------------------------------------------------- /SwiftPreview.xctemplate/UICollectionViewCellXIBSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 6 | 7 | override func awakeFromNib() { 8 | super.awakeFromNib() 9 | // Initialization code 10 | } 11 | 12 | } 13 | 14 | #if canImport(SwiftUI) && DEBUG 15 | import SwiftUI 16 | import SwiftPreview 17 | 18 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 19 | static var previews: some View { 20 | UIViewPreview { 21 | ___FILEBASENAMEASIDENTIFIER___() 22 | } 23 | } 24 | } 25 | #endif -------------------------------------------------------------------------------- /SwiftPreview.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |spec| 2 | spec.name = "SwiftPreview" 3 | spec.version = "1.0.0" 4 | spec.summary = "Preview template for UIkit based project" 5 | spec.homepage = "https://github.com/heoblitz/SwiftPreview" 6 | spec.license = "MIT" 7 | spec.author = { "heoblitz" => "qndlf22@naver.com" } 8 | spec.source = { :git => "https://github.com/heoblitz/SwiftPreview.git", :tag => spec.version.to_s } 9 | spec.source_files = "Sources/SwiftPreview/*.swift" 10 | spec.requires_arc = true 11 | spec.swift_version = "5.0" 12 | spec.ios.deployment_target = "13.0" 13 | end -------------------------------------------------------------------------------- /Templates/SwiftPreview.xctemplate/UICollectionViewCellXIBSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 6 | 7 | override func awakeFromNib() { 8 | super.awakeFromNib() 9 | // Initialization code 10 | } 11 | 12 | } 13 | 14 | #if canImport(SwiftUI) && DEBUG 15 | import SwiftUI 16 | import SwiftPreview 17 | 18 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 19 | static var previews: some View { 20 | UIViewPreview { 21 | ___FILEBASENAMEASIDENTIFIER___() 22 | } 23 | } 24 | } 25 | #endif -------------------------------------------------------------------------------- /SwiftPreview.xctemplate/UICollectionReusableViewXIBSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 6 | 7 | override func awakeFromNib() { 8 | super.awakeFromNib() 9 | // Initialization code 10 | } 11 | 12 | } 13 | 14 | #if canImport(SwiftUI) && DEBUG 15 | import SwiftUI 16 | import SwiftPreview 17 | 18 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 19 | static var previews: some View { 20 | UIViewPreview { 21 | ___FILEBASENAMEASIDENTIFIER___() 22 | } 23 | } 24 | } 25 | #endif 26 | -------------------------------------------------------------------------------- /Templates/SwiftPreview.xctemplate/UICollectionReusableViewXIBSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 6 | 7 | override func awakeFromNib() { 8 | super.awakeFromNib() 9 | // Initialization code 10 | } 11 | 12 | } 13 | 14 | #if canImport(SwiftUI) && DEBUG 15 | import SwiftUI 16 | import SwiftPreview 17 | 18 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 19 | static var previews: some View { 20 | UIViewPreview { 21 | ___FILEBASENAMEASIDENTIFIER___() 22 | } 23 | } 24 | } 25 | #endif 26 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.5 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "SwiftPreview", 8 | platforms: [.iOS(.v13), .tvOS(.v13)], 9 | products: [ 10 | .library( 11 | name: "SwiftPreview", 12 | targets: ["SwiftPreview"] 13 | ), 14 | ], 15 | dependencies: [], 16 | targets: [ 17 | .target( 18 | name: "SwiftPreview", 19 | dependencies: [] 20 | ), 21 | .testTarget( 22 | name: "SwiftPreviewTests", 23 | dependencies: ["SwiftPreview"] 24 | ), 25 | ] 26 | ) 27 | -------------------------------------------------------------------------------- /SwiftPreview.xctemplate/UIViewSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 6 | 7 | /* 8 | // Only override draw() if you perform custom drawing. 9 | // An empty implementation adversely affects performance during animation. 10 | override func draw(_ rect: CGRect) { 11 | // Drawing code 12 | } 13 | */ 14 | 15 | } 16 | 17 | #if canImport(SwiftUI) && DEBUG 18 | import SwiftUI 19 | import SwiftPreview 20 | 21 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 22 | static var previews: some View { 23 | UIViewPreview { 24 | ___FILEBASENAMEASIDENTIFIER___() 25 | } 26 | } 27 | } 28 | #endif -------------------------------------------------------------------------------- /Templates/SwiftPreview.xctemplate/UIViewSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 6 | 7 | /* 8 | // Only override draw() if you perform custom drawing. 9 | // An empty implementation adversely affects performance during animation. 10 | override func draw(_ rect: CGRect) { 11 | // Drawing code 12 | } 13 | */ 14 | 15 | } 16 | 17 | #if canImport(SwiftUI) && DEBUG 18 | import SwiftUI 19 | import SwiftPreview 20 | 21 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 22 | static var previews: some View { 23 | UIViewPreview { 24 | ___FILEBASENAMEASIDENTIFIER___() 25 | } 26 | } 27 | } 28 | #endif -------------------------------------------------------------------------------- /SwiftPreview.xctemplate/UITableViewCellSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 6 | 7 | override func awakeFromNib() { 8 | super.awakeFromNib() 9 | // Initialization code 10 | } 11 | 12 | override func setSelected(_ selected: Bool, animated: Bool) { 13 | super.setSelected(selected, animated: animated) 14 | 15 | // Configure the view for the selected state 16 | } 17 | 18 | } 19 | 20 | #if canImport(SwiftUI) && DEBUG 21 | import SwiftUI 22 | import SwiftPreview 23 | 24 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 25 | static var previews: some View { 26 | UIViewPreview { 27 | ___FILEBASENAMEASIDENTIFIER___() 28 | } 29 | } 30 | } 31 | #endif -------------------------------------------------------------------------------- /SwiftPreview.xctemplate/UITableViewCellXIBSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 6 | 7 | override func awakeFromNib() { 8 | super.awakeFromNib() 9 | // Initialization code 10 | } 11 | 12 | override func setSelected(_ selected: Bool, animated: Bool) { 13 | super.setSelected(selected, animated: animated) 14 | 15 | // Configure the view for the selected state 16 | } 17 | 18 | } 19 | 20 | #if canImport(SwiftUI) && DEBUG 21 | import SwiftUI 22 | import SwiftPreview 23 | 24 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 25 | static var previews: some View { 26 | UIViewPreview { 27 | ___FILEBASENAMEASIDENTIFIER___() 28 | } 29 | } 30 | } 31 | #endif -------------------------------------------------------------------------------- /Templates/SwiftPreview.xctemplate/UITableViewCellSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 6 | 7 | override func awakeFromNib() { 8 | super.awakeFromNib() 9 | // Initialization code 10 | } 11 | 12 | override func setSelected(_ selected: Bool, animated: Bool) { 13 | super.setSelected(selected, animated: animated) 14 | 15 | // Configure the view for the selected state 16 | } 17 | 18 | } 19 | 20 | #if canImport(SwiftUI) && DEBUG 21 | import SwiftUI 22 | import SwiftPreview 23 | 24 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 25 | static var previews: some View { 26 | UIViewPreview { 27 | ___FILEBASENAMEASIDENTIFIER___() 28 | } 29 | } 30 | } 31 | #endif -------------------------------------------------------------------------------- /Templates/SwiftPreview.xctemplate/UITableViewCellXIBSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 6 | 7 | override func awakeFromNib() { 8 | super.awakeFromNib() 9 | // Initialization code 10 | } 11 | 12 | override func setSelected(_ selected: Bool, animated: Bool) { 13 | super.setSelected(selected, animated: animated) 14 | 15 | // Configure the view for the selected state 16 | } 17 | 18 | } 19 | 20 | #if canImport(SwiftUI) && DEBUG 21 | import SwiftUI 22 | import SwiftPreview 23 | 24 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 25 | static var previews: some View { 26 | UIViewPreview { 27 | ___FILEBASENAMEASIDENTIFIER___() 28 | } 29 | } 30 | } 31 | #endif -------------------------------------------------------------------------------- /SwiftPreviewController.xctemplate/UITableViewControllerSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 6 | 7 | override func viewDidLoad() { 8 | super.viewDidLoad() 9 | } 10 | 11 | // MARK: - Table view data source 12 | override func numberOfSections(in tableView: UITableView) -> Int { 13 | return 0 14 | } 15 | 16 | override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 17 | return 0 18 | } 19 | } 20 | 21 | #if canImport(SwiftUI) && DEBUG 22 | import SwiftUI 23 | import SwiftPreview 24 | 25 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 26 | static var previews: some View { 27 | ViewControllerPreview { 28 | ___FILEBASENAMEASIDENTIFIER___() 29 | } 30 | } 31 | } 32 | #endif -------------------------------------------------------------------------------- /Templates/SwiftPreviewController.xctemplate/UITableViewControllerSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 6 | 7 | override func viewDidLoad() { 8 | super.viewDidLoad() 9 | } 10 | 11 | // MARK: - Table view data source 12 | override func numberOfSections(in tableView: UITableView) -> Int { 13 | return 0 14 | } 15 | 16 | override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 17 | return 0 18 | } 19 | } 20 | 21 | #if canImport(SwiftUI) && DEBUG 22 | import SwiftUI 23 | import SwiftPreview 24 | 25 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 26 | static var previews: some View { 27 | ViewControllerPreview { 28 | ___FILEBASENAMEASIDENTIFIER___() 29 | } 30 | } 31 | } 32 | #endif -------------------------------------------------------------------------------- /SwiftPreviewController.xctemplate/UITableViewControllerXIBSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 6 | 7 | override func viewDidLoad() { 8 | super.viewDidLoad() 9 | } 10 | 11 | // MARK: - Table view data source 12 | override func numberOfSections(in tableView: UITableView) -> Int { 13 | // #warning Incomplete implementation, return the number of sections 14 | return 0 15 | } 16 | 17 | override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 18 | // #warning Incomplete implementation, return the number of rows 19 | return 0 20 | } 21 | } 22 | 23 | #if canImport(SwiftUI) && DEBUG 24 | import SwiftUI 25 | import SwiftPreview 26 | 27 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 28 | static var previews: some View { 29 | UIViewControllerPreview { 30 | ___FILEBASENAMEASIDENTIFIER___() 31 | } 32 | } 33 | } 34 | #endif -------------------------------------------------------------------------------- /Templates/SwiftPreviewController.xctemplate/UITableViewControllerXIBSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 6 | 7 | override func viewDidLoad() { 8 | super.viewDidLoad() 9 | } 10 | 11 | // MARK: - Table view data source 12 | override func numberOfSections(in tableView: UITableView) -> Int { 13 | // #warning Incomplete implementation, return the number of sections 14 | return 0 15 | } 16 | 17 | override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 18 | // #warning Incomplete implementation, return the number of rows 19 | return 0 20 | } 21 | } 22 | 23 | #if canImport(SwiftUI) && DEBUG 24 | import SwiftUI 25 | import SwiftPreview 26 | 27 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 28 | static var previews: some View { 29 | UIViewControllerPreview { 30 | ___FILEBASENAMEASIDENTIFIER___() 31 | } 32 | } 33 | } 34 | #endif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Won Heo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /SwiftPreview.xctemplate/UICollectionReusableViewXIBSwift/___FILEBASENAME___.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Templates/SwiftPreview.xctemplate/UICollectionReusableViewXIBSwift/___FILEBASENAME___.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /SwiftPreviewController.xctemplate/UICollectionViewControllerXIBSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | private let reuseIdentifier = "Cell" 6 | 7 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 8 | 9 | override func viewDidLoad() { 10 | super.viewDidLoad() 11 | self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier) 12 | } 13 | 14 | // MARK: UICollectionViewDataSource 15 | override func numberOfSections(in collectionView: UICollectionView) -> Int { 16 | return 0 17 | } 18 | 19 | 20 | override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 21 | return 0 22 | } 23 | 24 | override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 25 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) 26 | return cell 27 | } 28 | } 29 | 30 | #if canImport(SwiftUI) && DEBUG 31 | import SwiftUI 32 | import SwiftPreview 33 | 34 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 35 | static var previews: some View { 36 | UIViewControllerPreview { 37 | ___FILEBASENAMEASIDENTIFIER___() 38 | } 39 | } 40 | } 41 | #endif -------------------------------------------------------------------------------- /Templates/SwiftPreviewController.xctemplate/UICollectionViewControllerXIBSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | private let reuseIdentifier = "Cell" 6 | 7 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 8 | 9 | override func viewDidLoad() { 10 | super.viewDidLoad() 11 | self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier) 12 | } 13 | 14 | // MARK: UICollectionViewDataSource 15 | override func numberOfSections(in collectionView: UICollectionView) -> Int { 16 | return 0 17 | } 18 | 19 | 20 | override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 21 | return 0 22 | } 23 | 24 | override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 25 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) 26 | return cell 27 | } 28 | } 29 | 30 | #if canImport(SwiftUI) && DEBUG 31 | import SwiftUI 32 | import SwiftPreview 33 | 34 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 35 | static var previews: some View { 36 | UIViewControllerPreview { 37 | ___FILEBASENAMEASIDENTIFIER___() 38 | } 39 | } 40 | } 41 | #endif -------------------------------------------------------------------------------- /Tests/SwiftPreviewTests/TestDoubles/DummyView.swift: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2021 Won Heo 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | // 23 | // DummyView.swift 24 | // SwiftPreview 25 | // 26 | // Created by won heo on 2021/10/02. 27 | // 28 | 29 | import UIKit 30 | 31 | class DummyView: UIView {} 32 | -------------------------------------------------------------------------------- /Tests/SwiftPreviewTests/TestDoubles/DummyViewController.swift: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2021 Won Heo 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | // 23 | // DummyViewController.swift 24 | // SwiftPreview 25 | // 26 | // Created by won heo on 2021/10/01. 27 | // 28 | 29 | import UIKit 30 | 31 | class DummyViewController: UIViewController {} 32 | -------------------------------------------------------------------------------- /SwiftPreviewController.xctemplate/UICollectionViewControllerSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | private let reuseIdentifier = "Cell" 6 | 7 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 8 | 9 | override func viewDidLoad() { 10 | super.viewDidLoad() 11 | // Register cell classes 12 | self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier) 13 | } 14 | 15 | // MARK: UICollectionViewDataSource 16 | override func numberOfSections(in collectionView: UICollectionView) -> Int { 17 | // #warning Incomplete implementation, return the number of sections 18 | return 0 19 | } 20 | 21 | 22 | override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 23 | // #warning Incomplete implementation, return the number of items 24 | return 0 25 | } 26 | 27 | override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 28 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) 29 | 30 | // Configure the cell 31 | 32 | return cell 33 | } 34 | } 35 | 36 | #if canImport(SwiftUI) && DEBUG 37 | import SwiftUI 38 | import SwiftPreview 39 | 40 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 41 | static var previews: some View { 42 | UIViewControllerPreview { 43 | ___FILEBASENAMEASIDENTIFIER___() 44 | } 45 | } 46 | } 47 | #endif -------------------------------------------------------------------------------- /SwiftPreviewController.xctemplate/UIViewControllerXIBSwift/___FILEBASENAME___.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Templates/SwiftPreviewController.xctemplate/UICollectionViewControllerSwift/___FILEBASENAME___.swift: -------------------------------------------------------------------------------- 1 | //___FILEHEADER___ 2 | 3 | import UIKit 4 | 5 | private let reuseIdentifier = "Cell" 6 | 7 | class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ { 8 | 9 | override func viewDidLoad() { 10 | super.viewDidLoad() 11 | // Register cell classes 12 | self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier) 13 | } 14 | 15 | // MARK: UICollectionViewDataSource 16 | override func numberOfSections(in collectionView: UICollectionView) -> Int { 17 | // #warning Incomplete implementation, return the number of sections 18 | return 0 19 | } 20 | 21 | 22 | override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 23 | // #warning Incomplete implementation, return the number of items 24 | return 0 25 | } 26 | 27 | override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 28 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) 29 | 30 | // Configure the cell 31 | 32 | return cell 33 | } 34 | } 35 | 36 | #if canImport(SwiftUI) && DEBUG 37 | import SwiftUI 38 | import SwiftPreview 39 | 40 | struct ___FILEBASENAMEASIDENTIFIER____Previews: PreviewProvider { 41 | static var previews: some View { 42 | UIViewControllerPreview { 43 | ___FILEBASENAMEASIDENTIFIER___() 44 | } 45 | } 46 | } 47 | #endif -------------------------------------------------------------------------------- /Templates/SwiftPreviewController.xctemplate/UIViewControllerXIBSwift/___FILEBASENAME___.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SwiftPreview 2 | 3 | XCode Preview template for UIkit based project. 4 | Support custom file template class inherit from UIView and UIViewController. 5 | 6 | ![](https://i.imgur.com/6Qr7fgp.png) 7 | 8 | ## How to use? 9 | 1. [Download Xcode Template](#Download_Xcode_Template) & [Install SwiftPreview](#Installation) 10 | 2. Xcode > New File (Command + N) 11 | You can choose Preview or PreviewController. 12 | 13 | ![](https://i.imgur.com/jHhcl2M.png) 14 | - Preview > (UIView, UITableViewCell, UICollectionViewCell, UICollectionReusableView) 15 | - PreviewController > (UIViewController, UITableViewController, UICollectionViewController) 16 | 17 | 3. Make file then preview will work. 18 | 19 | ## Download Xcode Template 20 | 21 | ### Auto Setup 22 | ```bash 23 | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/heoblitz/SwiftPreview/main/install.sh)" 24 | ``` 25 | 26 | ### Manual Setup 27 | ```bash 28 | git clone https://github.com/heoblitz/SwiftPreview.git 29 | cd SwiftPreview 30 | mkdir -p ~/Library/Developer/Xcode/Templates/File\ Templates/SwiftPreview 31 | cp -r Templates/. ~/Library/Developer/Xcode/Templates/File\ Templates/SwiftPreview 32 | ``` 33 | 34 | ### 35 | 36 | ## Installation 37 | 38 | ### Swift Package Manager 39 | Project > Project Dependencies > Add   `https://github.com/heoblitz/SwiftPreview` 40 | 41 | ### Cocoapods 42 | ```ruby 43 | pod 'SwiftPreview' 44 | ``` 45 | 46 | 47 | ## UnInstallation 48 | 1. Remove dependency 49 | 2. Delete template files 50 | ```bash 51 | rm -r ~/Library/Developer/Xcode/Templates/File\ Templates/SwiftPreview 52 | ``` 53 | 54 | ## License 55 | MIT 56 | -------------------------------------------------------------------------------- /SwiftPreview.xctemplate/UICollectionViewCellXIBSwift/___FILEBASENAME___.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Templates/SwiftPreview.xctemplate/UICollectionViewCellXIBSwift/___FILEBASENAME___.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /SwiftPreview.xctemplate/UITableViewCellXIBSwift/___FILEBASENAME___.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Templates/SwiftPreview.xctemplate/UITableViewCellXIBSwift/___FILEBASENAME___.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Sources/SwiftPreview/UIViewPreview.swift: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2021 Won Heo 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | // 23 | // UIViewPreview.swift 24 | // SwiftPreview 25 | // 26 | // Created by won heo on 2021/10/01. 27 | // 28 | 29 | import UIKit 30 | 31 | #if canImport(SwiftUI) 32 | import SwiftUI 33 | 34 | @available(iOS 13.0, tvOS 13.0, *) 35 | public struct UIViewPreview: UIViewRepresentable where Content : UIView { 36 | let builder: () -> Content 37 | 38 | public init(_ builder: @escaping () -> Content) { 39 | self.builder = builder 40 | } 41 | 42 | public func makeUIView(context: Self.Context) -> Content { 43 | return builder() 44 | } 45 | 46 | public func updateUIView(_ uiView: Self.UIViewType, context: Self.Context) {} 47 | } 48 | #endif 49 | -------------------------------------------------------------------------------- /Tests/SwiftPreviewTests/UIViewPreviewTests.swift: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2021 Won Heo 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | // 23 | // UIViewPreviewTests.swift 24 | // SwiftPreviewTests 25 | // 26 | // Created by won heo on 2021/10/02. 27 | // 28 | 29 | import SwiftUI 30 | import UIKit 31 | import XCTest 32 | @testable import SwiftPreview 33 | 34 | class UIViewPreviewTests: XCTestCase { 35 | var sut: UIViewPreview! 36 | 37 | override func setUpWithError() throws { 38 | sut = UIViewPreview { 39 | DummyView() 40 | } 41 | } 42 | 43 | override func tearDownWithError() throws { 44 | sut = nil 45 | } 46 | 47 | func testBuilder() throws { 48 | let view = sut.builder() 49 | XCTAssertTrue(view is DummyView) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Tests/SwiftPreviewTests/UIViewControllerPreviewTests.swift: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2021 Won Heo 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | // 23 | // UIViewControllerPreviewTests.swift 24 | // SwiftPreviewTests 25 | // 26 | // Created by won heo on 2021/10/01. 27 | // 28 | 29 | import SwiftUI 30 | import UIKit 31 | import XCTest 32 | @testable import SwiftPreview 33 | 34 | class UIViewControllerPreviewTests: XCTestCase { 35 | var sut: UIViewControllerPreview! 36 | 37 | override func setUpWithError() throws { 38 | sut = UIViewControllerPreview { 39 | DummyViewController() 40 | } 41 | } 42 | 43 | override func tearDownWithError() throws { 44 | sut = nil 45 | } 46 | 47 | func testBuilder() throws { 48 | let vc = sut.builder() 49 | XCTAssertTrue(vc is DummyViewController) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Sources/SwiftPreview/UIViewControllerPreview.swift: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // 3 | // Copyright (c) 2021 Won Heo 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | // 23 | // UIViewControllerPreview.swift 24 | // SwiftPreview 25 | // 26 | // Created by won heo on 2021/10/01. 27 | // 28 | 29 | import UIKit 30 | 31 | #if canImport(SwiftUI) 32 | import SwiftUI 33 | 34 | @available(iOS 13.0, tvOS 13.0, *) 35 | public struct UIViewControllerPreview: UIViewControllerRepresentable where Content : UIViewController { 36 | let builder: () -> Content 37 | 38 | public init(_ builder: @escaping () -> Content) { 39 | self.builder = builder 40 | } 41 | 42 | public func makeUIViewController(context: Self.Context) -> Content { 43 | return builder() 44 | } 45 | 46 | public func updateUIViewController(_ uiViewController: Self.UIViewControllerType, context: Self.Context) {} 47 | } 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /SwiftPreviewController.xctemplate/UITableViewControllerXIBSwift/___FILEBASENAME___.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Templates/SwiftPreviewController.xctemplate/UITableViewControllerXIBSwift/___FILEBASENAME___.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /SwiftPreviewController.xctemplate/UICollectionViewControllerXIBSwift/___FILEBASENAME___.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Templates/SwiftPreviewController.xctemplate/UICollectionViewControllerXIBSwift/___FILEBASENAME___.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # path 3 | XCODE_DIR=$HOME'/Library/Developer/Xcode' 4 | XCODE_TEMPLATE_DIR=$HOME'/Library/Developer/Xcode/Templates/File Templates/SwiftPreview' 5 | GIT_PATH="https://raw.githubusercontent.com/heoblitz/SwiftPreview/main/Templates" 6 | VIEW_PATH=$XCODE_TEMPLATE_DIR'/SwiftPreview.xctemplate' 7 | CONTROLLER_PATH=$XCODE_TEMPLATE_DIR'/SwiftPreviewController.xctemplate' 8 | 9 | init() { 10 | # check xcode folder 11 | if [ ! -d "$XCODE_DIR" ]; then 12 | echo "Error: XCODE is not installed 🤖" 13 | echo "${XCODE_DIR} is not exist" 14 | exit 1 15 | fi 16 | 17 | # check template folder 18 | if [ ! -d "$XCODE_TEMPLATE_DIR" ]; then 19 | echo "Add: Template folder 🗂" 20 | mkdir -p "$XCODE_TEMPLATE_DIR" 21 | echo "-> ${XCODE_TEMPLATE_DIR}" 22 | fi 23 | } 24 | 25 | install() { 26 | VIEWS=( 27 | "UICollectionReusableViewSwift" 28 | "UICollectionReusableViewXIBSwift" 29 | "UICollectionViewCellSwift" 30 | "UICollectionViewCellXIBSwift" 31 | "UITableViewCellSwift" 32 | "UITableViewCellXIBSwift" 33 | "UIViewSwift" 34 | ) 35 | 36 | CONTROLLERS=( 37 | "UICollectionViewControllerSwift" 38 | "UICollectionViewControllerXIBSwift" 39 | "UITableViewControllerSwift" 40 | "UITableViewControllerXIBSwift" 41 | "UIViewControllerSwift" 42 | "UIViewControllerXIBSwift" 43 | ) 44 | 45 | CORES=( 46 | "TemplateIcon-1016.png" 47 | "TemplateIcon-1016@2x.png" 48 | "TemplateInfo.plist" 49 | ) 50 | 51 | mkdir "$VIEW_PATH" 52 | mkdir "$CONTROLLER_PATH" 53 | 54 | for NAME in ${VIEWS[@]}; do 55 | CURRENT_PATH="${VIEW_PATH}/${NAME}" 56 | mkdir "$CURRENT_PATH" 57 | FILE_URL="${GIT_PATH}/SwiftPreview.xctemplate/${NAME}/___FILEBASENAME___.swift" 58 | download "$CURRENT_PATH" "$FILE_URL" "${NAME}/___FILEBASENAME___.swift" 59 | 60 | if [[ $NAME == *"XIB"* ]]; then 61 | FILE_URL="${GIT_PATH}/SwiftPreview.xctemplate/${NAME}/___FILEBASENAME___.xib" 62 | download "$CURRENT_PATH" "$FILE_URL" "${NAME}/___FILEBASENAME___.xib" 63 | fi 64 | done 65 | 66 | for NAME in ${CORES[@]}; do 67 | FILE_URL="${GIT_PATH}/SwiftPreview.xctemplate/${NAME}" 68 | download "$VIEW_PATH" "$FILE_URL" "${NAME}" 69 | done 70 | 71 | for NAME in ${CONTROLLERS[@]}; do 72 | CURRENT_PATH="${CONTROLLER_PATH}/${NAME}" 73 | mkdir "$CURRENT_PATH" 74 | FILE_URL="${GIT_PATH}/SwiftPreviewController.xctemplate/${NAME}/___FILEBASENAME___.swift" 75 | download "$CURRENT_PATH" "$FILE_URL" "${NAME}/___FILEBASENAME___.swift" 76 | 77 | if [[ $NAME == *"XIB"* ]]; then 78 | FILE_URL="${GIT_PATH}/SwiftPreviewController.xctemplate/${NAME}/___FILEBASENAME___.xib" 79 | download "$CURRENT_PATH" "$FILE_URL" "${NAME}/___FILEBASENAME___.xib" 80 | fi 81 | done 82 | 83 | for NAME in ${CORES[@]}; do 84 | FILE_URL="${GIT_PATH}/SwiftPreviewController.xctemplate/${NAME}" 85 | download "$CONTROLLER_PATH" "$FILE_URL" "${NAME}" 86 | done 87 | 88 | echo "Complete: SwiftPreview template installed 🖼" 89 | } 90 | 91 | download() { 92 | echo "Download: ${3} 🗳" 93 | cd "$1" && { curl -sSOL "$2" ; cd - > /dev/null ; } 94 | } 95 | 96 | init 97 | install 98 | -------------------------------------------------------------------------------- /Templates/SwiftPreviewController.xctemplate/TemplateInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SupportsSwiftPackage 5 | 6 | Kind 7 | Xcode.IDEFoundation.TextSubstitutionFileTemplateKind 8 | Description 9 | A Cocoa Touch class. 10 | Summary 11 | A Cocoa Touch class 12 | SortOrder 13 | 2 14 | DefaultCompletionName 15 | MyClass 16 | Platforms 17 | 18 | com.apple.platform.iphoneos 19 | 20 | Options 21 | 22 | 23 | Identifier 24 | productName 25 | Required 26 | 27 | Name 28 | Class: 29 | Description 30 | The name of the class to create 31 | Type 32 | text 33 | NotPersisted 34 | 35 | 36 | 37 | Identifier 38 | cocoaTouchSubclass 39 | Required 40 | YES 41 | Name 42 | Subclass of: 43 | Description 44 | What class to subclass in the new file 45 | Type 46 | class 47 | Default 48 | NSObject 49 | FallbackHeader 50 | #import <UIKit/UIKit.h> 51 | Values 52 | 53 | UIViewController 54 | UITableViewController 55 | UICollectionViewController 56 | 57 | Suffixes 58 | 59 | UIViewController 60 | ViewController 61 | UITableViewController 62 | TableViewController 63 | UICollectionViewController 64 | CollectionViewController 65 | 66 | 67 | 68 | Identifier 69 | XIB 70 | Name 71 | Also create XIB file 72 | Description 73 | Whether to create a XIB file with the same name 74 | Type 75 | checkbox 76 | RequiredOptions 77 | 78 | cocoaTouchSubclass 79 | 80 | UIViewController 81 | UITableViewController 82 | UICollectionViewController 83 | 84 | 85 | Default 86 | false 87 | NotPersisted 88 | 89 | 90 | 91 | Identifier 92 | languageChoice 93 | Required 94 | 95 | Name 96 | Language: 97 | Description 98 | The implementation language 99 | Type 100 | popup 101 | Default 102 | Swift 103 | MainTemplateFiles 104 | 105 | Swift 106 | ___FILEBASENAME___.swift 107 | 108 | AllowedTypes 109 | 110 | Swift 111 | 112 | public.swift-source 113 | 114 | 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /Templates/SwiftPreview.xctemplate/TemplateInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SupportsSwiftPackage 5 | 6 | Kind 7 | Xcode.IDEFoundation.TextSubstitutionFileTemplateKind 8 | Description 9 | A Preview 10 | Summary 11 | A Preview 12 | SortOrder 13 | 2 14 | DefaultCompletionName 15 | MyClass 16 | Platforms 17 | 18 | com.apple.platform.iphoneos 19 | 20 | Options 21 | 22 | 23 | Identifier 24 | productName 25 | Required 26 | 27 | Name 28 | Class: 29 | Description 30 | The name of the class to create 31 | Type 32 | text 33 | NotPersisted 34 | 35 | 36 | 37 | Identifier 38 | cocoaTouchSubclass 39 | Required 40 | YES 41 | Name 42 | Subclass of: 43 | Description 44 | What class to subclass in the new file 45 | Type 46 | class 47 | Default 48 | NSObject 49 | FallbackHeader 50 | #import <UIKit/UIKit.h> 51 | Values 52 | 53 | UIView 54 | UITableViewCell 55 | UICollectionViewCell 56 | UICollectionReusableView 57 | 58 | Suffixes 59 | 60 | UIView 61 | View 62 | UITableViewCell 63 | TableViewCell 64 | UICollectionViewCell 65 | CollectionViewCell 66 | UICollectionReusableView 67 | CollectionReusableView 68 | 69 | 70 | 71 | Identifier 72 | XIB 73 | Name 74 | Also create XIB file 75 | Description 76 | Whether to create a XIB file with the same name 77 | Type 78 | checkbox 79 | RequiredOptions 80 | 81 | cocoaTouchSubclass 82 | 83 | UITableViewCell 84 | UICollectionViewCell 85 | UICollectionReusableView 86 | 87 | 88 | Default 89 | false 90 | NotPersisted 91 | 92 | 93 | 94 | Identifier 95 | languageChoice 96 | Required 97 | 98 | Name 99 | Language: 100 | Description 101 | The implementation language 102 | Type 103 | popup 104 | Default 105 | Swift 106 | Values 107 | 108 | Swift 109 | 110 | MainTemplateFiles 111 | 112 | Swift 113 | ___FILEBASENAME___.swift 114 | 115 | AllowedTypes 116 | 117 | Swift 118 | 119 | public.swift-source 120 | 121 | 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /SwiftPreviewController.xctemplate/TemplateInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 25 | 26 | 27 | SupportsSwiftPackage 28 | 29 | Kind 30 | Xcode.IDEFoundation.TextSubstitutionFileTemplateKind 31 | Description 32 | A Cocoa Touch class. 33 | Summary 34 | A Cocoa Touch class 35 | SortOrder 36 | 2 37 | DefaultCompletionName 38 | MyClass 39 | Platforms 40 | 41 | com.apple.platform.iphoneos 42 | 43 | Options 44 | 45 | 46 | Identifier 47 | productName 48 | Required 49 | 50 | Name 51 | Class: 52 | Description 53 | The name of the class to create 54 | Type 55 | text 56 | NotPersisted 57 | 58 | 59 | 60 | Identifier 61 | cocoaTouchSubclass 62 | Required 63 | YES 64 | Name 65 | Subclass of: 66 | Description 67 | What class to subclass in the new file 68 | Type 69 | class 70 | Default 71 | NSObject 72 | FallbackHeader 73 | #import <UIKit/UIKit.h> 74 | Values 75 | 76 | UIViewController 77 | UITableViewController 78 | UICollectionViewController 79 | UICollectionViewCell 80 | UICollectionReusableView 81 | 82 | Suffixes 83 | 84 | UIViewController 85 | ViewController 86 | UITableViewController 87 | TableViewController 88 | UICollectionViewController 89 | CollectionViewController 90 | 91 | 92 | 93 | Identifier 94 | XIB 95 | Name 96 | Also create XIB file 97 | Description 98 | Whether to create a XIB file with the same name 99 | Type 100 | checkbox 101 | RequiredOptions 102 | 103 | cocoaTouchSubclass 104 | 105 | UIViewController 106 | UITableViewController 107 | UICollectionViewController 108 | 109 | 110 | Default 111 | false 112 | NotPersisted 113 | 114 | 115 | 116 | Identifier 117 | languageChoice 118 | Required 119 | 120 | Name 121 | Language: 122 | Description 123 | The implementation language 124 | Type 125 | popup 126 | Default 127 | Swift 128 | MainTemplateFiles 129 | 130 | Swift 131 | ___FILEBASENAME___.swift 132 | 133 | AllowedTypes 134 | 135 | Swift 136 | 137 | public.swift-source 138 | 139 | 140 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /SwiftPreview.xctemplate/TemplateInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 25 | 26 | 27 | SupportsSwiftPackage 28 | 29 | Kind 30 | Xcode.IDEFoundation.TextSubstitutionFileTemplateKind 31 | Description 32 | A Preview 33 | Summary 34 | A Preview 35 | SortOrder 36 | 2 37 | DefaultCompletionName 38 | MyClass 39 | Platforms 40 | 41 | com.apple.platform.iphoneos 42 | 43 | Options 44 | 45 | 46 | Identifier 47 | productName 48 | Required 49 | 50 | Name 51 | Class: 52 | Description 53 | The name of the class to create 54 | Type 55 | text 56 | NotPersisted 57 | 58 | 59 | 60 | Identifier 61 | cocoaTouchSubclass 62 | Required 63 | YES 64 | Name 65 | Subclass of: 66 | Description 67 | What class to subclass in the new file 68 | Type 69 | class 70 | Default 71 | NSObject 72 | FallbackHeader 73 | #import <UIKit/UIKit.h> 74 | Values 75 | 76 | UIView 77 | UITableViewCell 78 | UICollectionViewCell 79 | UICollectionReusableView 80 | 81 | Suffixes 82 | 83 | UIView 84 | View 85 | UITableViewCell 86 | TableViewCell 87 | UICollectionViewCell 88 | CollectionViewCell 89 | UICollectionReusableView 90 | CollectionReusableView 91 | 92 | 93 | 94 | Identifier 95 | XIB 96 | Name 97 | Also create XIB file 98 | Description 99 | Whether to create a XIB file with the same name 100 | Type 101 | checkbox 102 | RequiredOptions 103 | 104 | cocoaTouchSubclass 105 | 106 | UITableViewCell 107 | UICollectionViewCell 108 | UICollectionReusableView 109 | 110 | 111 | Default 112 | false 113 | NotPersisted 114 | 115 | 116 | 117 | Identifier 118 | languageChoice 119 | Required 120 | 121 | Name 122 | Language: 123 | Description 124 | The implementation language 125 | Type 126 | popup 127 | Default 128 | Swift 129 | Values 130 | 131 | Swift 132 | 133 | MainTemplateFiles 134 | 135 | Swift 136 | ___FILEBASENAME___.swift 137 | 138 | AllowedTypes 139 | 140 | Swift 141 | 142 | public.swift-source 143 | 144 | 145 | 146 | 147 | 148 | 149 | --------------------------------------------------------------------------------