GithubHelp home page GithubHelp logo

andreinagy / swiftconstgen Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 30 KB

Tool that generates a swift constants file from resource files names.

License: MIT License

Swift 15.52% Ruby 72.51% Shell 11.97%

swiftconstgen's Introduction

SwiftFilesConstGen

Tool that generates a swift constants file from resource files names.

Table of Contents

  1. Installation
  2. Demo
  3. Usage

Overview

What you do:

guard let url = Bundle.main.url(forResource: "ErrorProneResourceFileNameWhichCanBeChangedWithouyNoticing", 
withExtension: nil) else {
	return
}

What you want to do:

guard let url = Bundle.main.url(forResource: Files.fileName, 
withExtension: nil) else {
	return
}
  • Get safety for free.
  • Autocomplete.
  • Build errors when constants change.

SwiftFilesConstGen overview

Installation

  • Navigate to the desired directory in the terminal (eg. in the project's bin/ folder)
  • run curl -O https://raw.githubusercontent.com/andreinagy/SwiftConstGen/master/swiftFilesConstGen.rb
  • run chmod +x swiftFilesConstGen.rb
  • Profit

Optionally you can add it as a build phase to get a fresh constants file.

"$PROJECT_DIR/bin/swiftFilesConstGen.rb" -i "$SRCROOT/$PROJECT_NAME/Resources/" -o "$SRCROOT/$PROJECT_NAME/Generated/" -e json -n JSONFiles
  • Script location: project's bin directory
  • Input files location Project/Resources/
  • Input files extension json
  • Output location Project/Generated/
  • Output file JSONFiles-generated.swift

Usage

Run in the terminal:

./swiftFilesConstGen -i path/to/files -o output/path -e json -n JSONFiles
  • It searches for all files ending with json in path/to/files
  • Creates JSONFiles-generated.swift containing constants with the files names.
  • Handles replaces the spaces and hyphens with underscores. Files that start with a number get an a prepended.

Sample output:

// Generated by swiftFilesConstGen
// Input directory: TestInput/
// Files extension: json
// Struct name: JSONFiles
// Do not modify manually

// swiftlint:disable all
struct JSONFiles {

    static let fileExtension = "json"
    
    static let myOtherFile = "My--Other.File"
    static let myFile = "My-File"

}
// swiftlint:enable all

swiftconstgen's People

Contributors

andreinagy avatar

Watchers

 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.