Available thruCocoapods
Latest1.0.0.beta.1
Homepagehttps://github.com/mac-cain13/R.swift
LicenseMIT

R.swift Version License Platform Build status

Get strong typed, autocompleted resources like images, fonts and segues in Swift projects

Why use this?

It makes your code that uses resources:

  • Fully typed, less casting and guessing what a method will return
  • Compiletime checked, no more incorrect strings that make your app crash at runtime
  • Autocompleted, never have to guess that image name again

Currently you type:

let icon = UIImage(named: "settings-icon")
let font = UIFont(name: "San Francisco", size: 42)
let viewController = CustomViewController(nibName: "CustomView", bundle: nil)

With R.swift it becomes:

let icon = R.image.settingsIcon
let font = R.font.sanFrancisco(size: 42)
let viewController = CustomViewController(nib: R.nib.customView)

Check out more examples of R.swift based code!

Demo

Autocompleted images:

Autocompleted images

Compiletime checked images:

Compiletime checked images

This is only the beginning, check out more examples!

Features

After installing R.swift into your project you can use the R-struct to access resources. If the struct is outdated just build and R.swift will correct any missing/changed/added resources.

R.swift currently supports these types of resources:

Runtime validation with R.validate():

  • If images used in storyboards are available
  • If view controllers with storyboard identifiers can be loaded

Q&A

Installation

CocoaPods is the recommended way of installation, as this avoids including any binary files into your project.

CocoaPods (recommended)

There is also a short video of this instruction.

  1. Add pod 'R.swift' to your Podfile and run pod install
  2. In XCode: Click on your project in the file list, choose your target under TARGETS, click the Build Phases tab and add a New Run Script Phase by clicking the little plus icon in the top left
  3. Drag the new Run Script phase above the Compile Sources phase and below Check Pods Manifest.lock, expand it and paste the following script: "$PODS_ROOT/R.swift/rswift" "$SRCROOT"
  4. Build your project, in Finder you will now see a R.generated.swift in the $SRCROOT-folder, drag the R.generated.swift files into your project and uncheck Copy items if needed

Tip: Add the *.generated.swift pattern to your .gitignore file to prevent unnecessary conflicts.

Manually

  1. Download a R.swift release, unzip it and put it into your source root directory
  2. In XCode: Click on your project in the file list, choose your target under TARGETS, click the Build Phases tab and add a New Run Script Phase by clicking the little plus icon in the top left
  3. Drag the new Run Script phase above the Compile Sources phase, expand it and paste the following script: "$SRCROOT/rswift" "$SRCROOT"
  4. Build your project, in Finder you will now see a R.generated.swift in the $SRCROOT-folder, drag the R.generated.swift files into your project and uncheck Copy items if needed

Tip: Add the *.generated.swift pattern to your .gitignore file to prevent unnecessary conflicts.

Contribute

Please post any issues, questions and compliments in the GitHub issue tracker and feel free to submit pull request with fixes and improvements. Keep in mind; a good pull request is small, forked from the develop-branch and well explained. It also should benefit most of the users.

License

R.swift is created by Mathijs Kadijk and released under a MIT License.

Latest podspec

{
    "name": "R.swift",
    "version": "1.0.0.beta.1",
    "license": "MIT",
    "summary": "Get strong typed, autocompleted resources like images, fonts and segues in Swift projects",
    "description": "R.swift is a tool to get strong typed, autocompleted resources like images, fonts and segues in Swift projects.nn* Never type string identifiers againn* Supports images, fonts, storyboards, nibs, segues, reuse identifiers and moren* Compile time checks and errors instead of runtime crashes",
    "homepage": "https://github.com/mac-cain13/R.swift",
    "documentation_url": "https://github.com/mac-cain13/R.swift/tree/master/Documentation",
    "screenshots": [
        "https://raw.githubusercontent.com/mac-cain13/R.swift/master/Documentation/Images/DemoUseImage.gif",
        "https://raw.githubusercontent.com/mac-cain13/R.swift/master/Documentation/Images/DemoRenameImage.gif"
    ],
    "authors": {
        "Mathijs Kadijk": "[email protected]"
    },
    "social_media_url": "https://twitter.com/mac_cain13",
    "requires_arc": true,
    "source": {
        "http": "https://github.com/mac-cain13/R.swift/releases/download/v1.0.0.beta.1/rswift-1.0.0.beta.1.zip"
    },
    "platforms": {
        "ios": "8.0",
        "tvos": "9.0"
    },
    "dependencies": {
        "R.swift.Library": [
            "~> 1.0.0.beta.1"
        ]
    },
    "preserve_paths": "rswift"
}

Pin It on Pinterest

Share This