Popularity
4.6
Stable
Activity
2.7
-
360
8
13

Code Quality Rank: L4
Monthly Downloads: 0
Programming language: Swift
License: MIT License
Tags: Tools    
Latest version: v1.2.0

Shark alternatives and similar libraries

Based on the "Tools" category

Do you think we are missing an alternative of Shark or a related project?

Add another 'Tools' Library

README

Shark

Build Status

Shark has been rewritten from scratch and now requires Xcode 10.2 / Swift 5

Shark is a Swift command line tool that generates type safe enums for your image assets, color assets and localizations.

Because Shark reads your .xcodeproj to find these assets, the setup is extremely simple.

Installation

Brew:

brew install kaandedeoglu/formulae/shark

Manually:

Clone the project, then do:

> swift build -c release --disable-sandbox
> cp ./build/release/Shark /usr/local/bin

You can then verify the installation by doing

shark --help

Setup

The easiest way to set up Shark is by adding a new Run Script phase to your build phases. This build phase should ideally run before the Compile Sources phase.

  • Add a new Run Script phase to your target. The script body should look like: bash if [ -x "$(command -v shark)" ]; then shark $PROJECT_FILE_PATH $PROJECT_DIR/$PROJECT_NAME fi

the if/else block makes sure that Shark is run only if it's installed on the current machine.

  • Build your project. You should now see a file named Shark.swift in your project folder.
  • Add this file to your project. Voila! The file will be updated every time the project is built!
  • Alternatively you can do the following: bash # Write to a specific file called MyAssets.swift shark $PROJECT_FILE_PATH $PROJECT_DIR/$PROJECT_NAME/MyAssets.swift
  # Write to a specific file in a different folder
  shark $PROJECT_FILE_PATH $PROJECT_DIR/$PROJECT_NAME/Utility/MyAssets.swift

Flags

Shark also accepts some flags to configure behavior

--name

By default, the top level enum everything else lives under is called - you guessed it - Shark. You can change this by using the --name flag.

  shark $PROJECT_FILE_PATH $PROJECT_DIR/$PROJECT_NAME --name Assets

--locale

By default, Shark will try to find English localizations to generate the localizations enum. If there are no English .strings file in your project, or you'd like Shark to take another localization as base, you can specify the language code with the --locale flag.

# Use Spanish localizations for generation
shark $PROJECT_FILE_PATH $PROJECT_DIR/$PROJECT_NAME --locale es

--target

In case your Xcode project has multiple application targets, you should specify which one Shark should look at by using the --target flag.

shark $PROJECT_FILE_PATH $PROJECT_DIR/$PROJECT_NAME --target MyAppTarget

--help

Prints the overview, example usage and available flags to the console.

Sample output

Below is a sample output generated by Shark. As you can see, the top level enum Shark contains three enums inside. I (Images), L (Localizations) and C (Colors). Example usage looks like

imageView.image = Shark.I.TaskIcons.task_icon_clean
label.text = Shark.L.button.login
view.backgroundColor = Shark.C.blue1

There are a few things to notice:

  • Image assets are namespaced by folder. For example all the images in your .xcassets folder that are contained in a folder called TaskIcons will be listed under an enum called TaskIcons.
  • Localizations are namespaced with separators. Currently Shark uses the dot symbol . as the separator. For example given two strings "button.login" and "button.logout", Shark will generate the following:
public enum L {
    public enum button {
        /// Login
        public static var login: String { return NSLocalizedString("button.login", comment: "") }

        /// Logout
        public static var logout: String { return NSLocalizedString("button.logout", comment: "") }
    }
}

You can see the sample below:

// Shark.swift
// Generated by Shark https://github.com/kaandedeoglu/Shark

import UIKit

public enum Shark {
    public enum I {
        public enum TaskIcons {
            public static var task_icon_clean: UIImage { return UIImage(named:"task_icon_clean")! }
            public static var task_icon_fallback: UIImage { return UIImage(named:"task_icon_fallback")! }
            public static var task_icon_replacebatteries: UIImage { return UIImage(named:"task_icon_replacebatteries")! }
            public static var task_icon_replacezipper: UIImage { return UIImage(named:"task_icon_replacezipper")! }
        }

        public static var back_image: UIImage { return UIImage(named:"back_image")! }
        public static var icon_banner_retry: UIImage { return UIImage(named:"icon-banner-retry")! }
        public static var icon_no_internet: UIImage { return UIImage(named:"icon-no-internet")! }
        public static var icon_paused_shift: UIImage { return UIImage(named:"icon-paused-shift")! }
        public static var input_icon_camera: UIImage { return UIImage(named:"input-icon-camera")! }
        public static var input_icon_invalid: UIImage { return UIImage(named:"input-icon-invalid")! }
        public static var input_icon_show_password: UIImage { return UIImage(named:"input-icon-show-password")! }
        public static var map_location_on: UIImage { return UIImage(named:"map-location-on")! }
        public static var menu_icon: UIImage { return UIImage(named:"menu-icon")! }
        public static var modal_checkbox_active: UIImage { return UIImage(named:"modal-checkbox-active")! }
        public static var modal_checkbox_inactive: UIImage { return UIImage(named:"modal-checkbox-inactive")! }
        public static var modal_icon_cancel: UIImage { return UIImage(named:"modal-icon-cancel")! }
        public static var modal_icon_navigate: UIImage { return UIImage(named:"modal-icon-navigate")! }
    }    

    public enum C {
        public static var backgroundColor: UIColor { return UIColor(named: "backgroundColor")! }
        public static var blue1: UIColor { return UIColor(named: "blue1")! }
        public static var blue2: UIColor { return UIColor(named: "blue2")! }
        public static var blue3: UIColor { return UIColor(named: "blue3")! }
        public static var gray1: UIColor { return UIColor(named: "gray1")! }
        public static var gray2: UIColor { return UIColor(named: "gray2")! }
        public static var gray3: UIColor { return UIColor(named: "gray3")! }
        public static var green1: UIColor { return UIColor(named: "green1")! }
        public static var green2: UIColor { return UIColor(named: "green2")! }
        public static var green3: UIColor { return UIColor(named: "green3")! }
        public static var red1: UIColor { return UIColor(named: "red1")! }
        public static var red2: UIColor { return UIColor(named: "red2")! }
        public static var red3: UIColor { return UIColor(named: "red3")! }
        public static var violet1: UIColor { return UIColor(named: "violet1")! }
        public static var violet2: UIColor { return UIColor(named: "violet2")! }
        public static var violet3: UIColor { return UIColor(named: "violet3")! }
    }

    public enum L {
        public enum banner {
            public enum bluetooth_controller_failed {
                /// Cannot create the ble connection to the scooter, this is most likely a backend issue, please contact your fleet operator.
                public static var title: String { return NSLocalizedString("banner.bluetooth_controller_failed.title", comment: "") }
            }

            public enum check_out_next_step_fetch_failed {
                /// Check out succeeded, but fetching the next step failed, please try again.
                public static var message: String { return NSLocalizedString("banner.check_out_next_step_fetch_failed.message", comment: "") }
            }

            public enum generic {
                /// Error
                public static var title: String { return NSLocalizedString("banner.generic.title", comment: "") }
            }

            public enum invalid_credentials {
                /// Wrong email & password combination
                public static var title: String { return NSLocalizedString("banner.invalid_credentials.title", comment: "") }
            }

            public enum login {
                /// Login request failed, please try again
                public static var message: String { return NSLocalizedString("banner.login.message", comment: "") }
            }

            public enum no_network_connection {
                /// No internet connection
                public static var title: String { return NSLocalizedString("banner.no_network_connection.title", comment: "") }
            }

            public enum request_failed {
                /// Request failed, please try again
                public static var title: String { return NSLocalizedString("banner.request_failed.title", comment: "") }
            }

            public enum retry {
                /// Please try again
                public static var message: String { return NSLocalizedString("banner.retry.message", comment: "") }
            }
        }

        public enum button {
            /// Connecting...
            public static var connecting: String { return NSLocalizedString("button.connecting", comment: "") }

            /// Login
            public static var login: String { return NSLocalizedString("button.login", comment: "") }

            /// Logout
            public static var logout: String { return NSLocalizedString("button.logout", comment: "") }

            /// Navigate
            public static var navigate: String { return NSLocalizedString("button.navigate", comment: "") }

            /// Okay
            public static var okay: String { return NSLocalizedString("button.okay", comment: "") }

            /// Remember my choice
            public static var remember_my_choice: String { return NSLocalizedString("button.remember_my_choice", comment: "") }

            /// Retry
            public static var retry: String { return NSLocalizedString("button.retry", comment: "") }

            /// Start Task
            public static var start_task: String { return NSLocalizedString("button.start_task", comment: "") }

            /// Unlock
            public static var unlock: String { return NSLocalizedString("button.unlock", comment: "") }

            /// Unlocking...
            public static var unlocking: String { return NSLocalizedString("button.unlocking", comment: "") }
        }

        public enum error {
            public enum generic {
                /// Error
                public static var title: String { return NSLocalizedString("error.generic.title", comment: "") }
            }

            public enum location_required {
                /// Turn on location services to allow Runner to determine your location
                public static var message: String { return NSLocalizedString("error.location_required.message", comment: "") }

                /// Location required
                public static var title: String { return NSLocalizedString("error.location_required.title", comment: "") }
            }

            /// Not a valid email address
            public static var invalid_email: String { return NSLocalizedString("error.invalid_email", comment: "") }

            /// Password must be at least 8 characters
            /// include upper and lowercase letters,
            /// numbers and special characters
            public static var invalid_password: String { return NSLocalizedString("error.invalid_password", comment: "") }

            /// Starting Runner failed with error: %@
            public static func loading_failed(_ value1: String) -> String {
                return String(format: NSLocalizedString("error.loading_failed", comment: ""), value1)
            }
        }
    }
}

License

The MIT License (MIT)

Copyright (c) 2019 Kaan Dedeoglu

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


*Note that all licence references and agreements mentioned in the Shark README section above are relevant to that project's source code only.