Code Monkey home page Code Monkey logo

uiviewpreview's Introduction

Swift Package Manager iOS 13.0 + tvOS 13.0

Mattt's beautiful gist to gain SwiftUI previews for your UIViews turned into Swift Package.

UIViewPreview Swift Package

Swift Package contains:

  • UIViewPreview
  • UIViewControllerPreview

Please read more about the use-cases for UIViewPreview in the NSHipster blogpost: https://nshipster.com/swiftui-previews/

Requirements:

  • macOS Catalina
  • Xcode 11.0 and above
  • Swift 5.1 and above
  • iOS 13.0 and above
  • tvOS 13.0 and above

Installation

Swift Package Manager

Add .package(url: "https://github.com/bielikb/UIViewPreview.git", from: "1.0.0") to your Package.swift file's dependencies.

If youre using Xcode 11.0 add UIViewPreview Swift Package to your target(s) using Xcode.

PreviewProvider (Official Apple Docs)

/// Produces view previews in Xcode.
///
/// Xcode statically discovers types that conform to `PreviewProvider` and
/// generates previews in the canvas for each provider it discovers.
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public protocol PreviewProvider : _PreviewProvider

Example:

import UIViewPreview

#if canImport(SwiftUI) && DEBUG
import SwiftUI
@available(iOS 13.0, *)
struct Label_Preview: PreviewProvider {
    static var previews: some View {
        UIViewPreview {
            let label = UILabel()
            label.frame = CGRect(origin: .zero,
                                 size: CGSize(width: 100, height: 100))
            label.text = "Text previewed in SwiftUI Preview"
            return label
        }
    }
}
#endif

Sample

LICENSE

https://unlicense.org

uiviewpreview's People

Contributors

bielikb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.