Swiftpack.co - tonyarnold/resourceror as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by tonyarnold.
tonyarnold/resourceror v0.2-alpha
Command-line tool to generate Swift static variables for images, XIBs, Storyboards and their contents
⭐️ 16
🕓 4 years ago
macOS
.package(url: "https://github.com/tonyarnold/resourceror.git", from: "v0.2-alpha")

Resourceror

This tool will generate static variables as extensions to the common AppKit types that accepted typed names, i.e.:

// Resourceror outputs the following, which you can add to your project:
extension NSImage {
    static let backgroundImage = NSImage(named: "background-image")
}

// Which means you can now do the following:
let backgroundImage = NSImage.backgroundImage

Neato!

Resourceror currently supports extensions on NSImage, NSNib, NSStoryboard, NSStoryboard.SceneIdentifier, NSStoryboardSegue.Identifier and NSUserInterfaceItemIdentifier. Feel free to submit PRs for anything else you'd like to see generated.

It's not quite finished, but you should be able to use it. The project lacks tests, the code is not polished, and everything needs a bit of work - it meets my needs, and it might be useful to you.

Usage

Basically, you run this command against a directory containing your images, XIBs, and Storyboards, and it will print a nicely sorted list of properly typed Swift static variables for your resources.

swift run resourceror generate $PATH_TO_YOUR_DIRECTORY --exclude first_directory second_directory

Requirements

  • macOS 10.13 or newer
  • Swift 5.2 or newer

Notes

If you use SwiftLint, you'll probably need to surround the output code with commands to disable some checks, like so:

// swiftlint:disable file_length
// swiftlint:disable force_unwrap
// swiftlint:disable identifier_name

extension NSImage {
    // …
}

extension NSNib {
    // …
}

extension NSStoryboard {
    // …
}

extension NSStoryboard.SceneIdentifier {
    // …
}

extension NSStoryboardSegue.Identifier {
    // …
}

extension NSUserInterfaceItemIdentifier {
    // …
}

GitHub

link
Stars: 16
Last commit: 4 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

xcassets, oh my!
4 years ago

📦

This pre-release adds support for scanning resources housed in xcassets bundles, including any namespaces.

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