mac-cain13 /R.swift

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

★ 9,549⑂ 773👁 107⑃ 277● 666▤ 115
SwiftMITCreated 2014-12-11
Download: 7.8.07.8.0 ↓7.8.02024-11-05
+0
Daily
9,549
stars
773
forks
107
watchers
277
prs
666
issues
115
releases

README

R.swift   !Platform

_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
- Compile time checked, no more incorrect strings that make your app crash at runtime
- Autocompleted, never have to guess that image name again

Currently you type:
swift
let icon = UIImage(named: "settings-icon")
let font = UIFont(name: "San Francisco", size: 42)
let color = UIColor(named: "indicator highlight")
let viewController = CustomViewController(nibName: "CustomView", bundle: nil)
let string = String(format: NSLocalizedString("welcome.withName", comment: ""), locale: NSLocale.current, "Arthur Dent")


With R.swift it becomes:
swift
let icon = R.image.settingsIcon()
let font = R.font.sanFrancisco(size: 42)
let color = R.color.indicatorHighlight()
let viewController = CustomViewController(nib: R.nib.customView)
let string = R.string.localizable.welcomeWithName("Arthur Dent")


Check out more examples or hear about how Fabric.app uses R.swift!

 Demo

Autocompleted images:

!Autocompleted images

Compiletime checked images:

!Compiletime checked images

This is only the beginning, check out more examples!

 CocoaHeadsNL presentation

Mathijs Kadijk presented R.swift at the September 2016 CocoaHeadsNL meetup.
Talking about the ideas behind R.swift and demonstrating how to move from plain stringly-typed iOS code to statically typed code.



 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:
- Images
- Fonts
- Resource files
- Colors
- Localized strings
- Storyboards
- Segues
- Nibs
- Reusable cells
- Project
- Entitlements
- Info.plist

Runtime validation with R.validate():
- If all images used in storyboards and nibs are available
- If all named colors used in storyboards and nibs are available
- If all view controllers with storyboard identifiers can be loaded
- If all custom fonts can be loaded

 Q&A

- Why was R.swift created?
- Why should I choose R.swift over alternative X or Y?
- What are the requirements to run R.swift?
- How to fix missing imports in the generated file?
- How to use classes with the same name as their module?
- Can I ignore resources?
- Can I use R.swift in a library?
- How does R.swift work?
- How to upgrade to a new major version?
- How can I only run specific generators?

 Installation

As of Rswift 7, Swift Package Manager is the recommended method of installation.

Demo video: Updating from R.swift 6 to Rswift 7 (Starting at 1:06, this describes the installation of Rswift 7).

 Xcode project using SPM (Recommended)

Demo Video: Install R.swift in Xcode with SPM

1. In Project Settings, on the tab "Package Dependencies", click "+", search for https://github.com/mac-cain13/R.swift a

Top issues

Latest release

7.8.0 7.8.0 2024-11-05
Add support for Xcode 16 file system Folders (https://github.com/mac-cain13/R.swift/pull/921)

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON