All Projects → SysdataSpA → R.objc

SysdataSpA / R.objc

Licence: apache-2.0
Get autocompleted resources like images, localized strings and storyboards in ObjC projects

Programming Languages

objc
23 projects

Projects that are alternatives of or similar to R.objc

Swiftgen
The Swift code generator for your assets, storyboards, Localizable.strings, … — Get rid of all String-based APIs!
Stars: ✭ 7,580 (+8139.13%)
Mutual labels:  code-generator, localization, uiimage
R.swift
Strong typed, autocompleted resources like images, fonts and segues in Swift projects
Stars: ✭ 8,419 (+9051.09%)
Mutual labels:  xcode, tvos, code-generator
Stringz
A lightweight and powerful editor for localizing iOS, macOS, tvOS, and watchOS applications.
Stars: ✭ 440 (+378.26%)
Mutual labels:  xcode, tvos, localization
Swiftui Grid
🚀 SwiftUI Grid layout with custom styles
Stars: ✭ 872 (+847.83%)
Mutual labels:  xcode, tvos
Swiftui
A collaborative list of awesome SwiftUI resources. Feel free to contribute!
Stars: ✭ 774 (+741.3%)
Mutual labels:  xcode, tvos
Exhibit
Exhibit is a managed screensaver App for tvOS.
Stars: ✭ 19 (-79.35%)
Mutual labels:  xcode, tvos
Sqlitelib
Easily build a custom SQLite static library for use in macOS and iOS frameworks and apps.
Stars: ✭ 38 (-58.7%)
Mutual labels:  xcode, tvos
Swiftgif
[UNMAINTAINED] 🌠 A small UIImage extension with gif support
Stars: ✭ 1,255 (+1264.13%)
Mutual labels:  xcode, uiimage
Swiftysound
SwiftySound is a simple library that lets you play sounds with a single line of code.
Stars: ✭ 995 (+981.52%)
Mutual labels:  xcode, tvos
Bartycrouch
Localization/I18n: Incrementally update/translate your Strings files from .swift, .h, .m(m), .storyboard or .xib files.
Stars: ✭ 1,032 (+1021.74%)
Mutual labels:  xcode, localization
Ioslocalizationeditor
Simple macOS editor app to help you manage iOS and macOS app localizations by allowing you to edit all the translations side by side
Stars: ✭ 1,066 (+1058.7%)
Mutual labels:  xcode, localization
Flightanimator
Advanced Natural Motion Animations, Simple Blocks Based Syntax
Stars: ✭ 588 (+539.13%)
Mutual labels:  xcode, tvos
Xcake
🍰 Describe Xcode projects in a human readable format and (re)generate one on demand.
Stars: ✭ 549 (+496.74%)
Mutual labels:  xcode, tvos
Apprepositorytemplate
The easiest way to start a new application project without any manual configuration
Stars: ✭ 24 (-73.91%)
Mutual labels:  xcode, tvos
Sablurimageview
You can use blur effect and it's animation easily to call only two methods.
Stars: ✭ 538 (+484.78%)
Mutual labels:  tvos, uiimage
Nord Xcode
An arctic, north-bluish clean and elegant Xcode color theme.
Stars: ✭ 63 (-31.52%)
Mutual labels:  xcode, tvos
Audioindicatorbars
AIB indicates for your app users which audio is playing. Just like the Podcasts app.
Stars: ✭ 279 (+203.26%)
Mutual labels:  xcode, tvos
Solarized Dark For Xcode
Solarized Dark Theme for Xcode. Compatible with all modern versions of Xcode since 2013!
Stars: ✭ 358 (+289.13%)
Mutual labels:  xcode, tvos
Fugen
Command line tool for exporting resources and generating code from your Figma files
Stars: ✭ 41 (-55.43%)
Mutual labels:  xcode, tvos
Luautocompleteview
Highly configurable autocomplete view that is attachable to any UITextField
Stars: ✭ 55 (-40.22%)
Mutual labels:  xcode, autocomplete

R.objc

Version License Platform

Introduction

Freely inspired by R.swift (Thank you, guys!): get autocompleted localizable strings, asset catalogue images names and storyboard objects.

You can have:

  • Compile time check: no more incorrect strings that make your app crash at runtime

  • Autocompletion: never have to guess that image name again

Installation

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

Cocoapods

  1. Add pod 'R.objc' to your Podfile and run pod install

  2. In XCode, click on your project in the Project Navigator

  3. 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

  4. Drag the new Run Script phase above the Compile Sources phase, expand it and paste the following script: 

    "${PODS_ROOT}/R.objc/Robjc" -p "$SRCROOT"
    

    (after -p option, you have to specify the root folder of your project, from where to scan your code)

  5. Build your project; in Finder you will now see R.h and R.m files in the $SRCROOT folder: drag them into your project and uncheck Copy items if needed

  6. Repeat point 3 and 4 for every target in your project

Manual

  1. Download latest version from the releases section

  2. Unzip in a folder anywhere you want.

  3. In XCode, click on your project in the Project Navigator

  4. 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

  5. Drag the new Run Script phase above the Compile Sources phase, expand it and paste the following script: 

    "<path to the unzipped folder>/Robjc" -p "$SRCROOT"
    

    (we suggest to unzip the folder somewhere within your project folder, in order to use the $SRCROOT shortcut for the path. Don't add anything to your Xcode project, or it won't build anymore) (after -p option, you have to specify the root folder of your project, from where to scan your code)

  6. Build your project; in Finder you will now see R.h and R.m files in the $SRCROOT folder: drag them into your project and uncheck Copy items if needed

  7. Repeat point 3 and 4 for every target in your project

At every build, the generated file will update automatically and there's no need to do anything.

Normally, you would write code like this:

[self.buttonProceed setTitle:NSLocalizedString(@"home_proceed", nil) forState:UIControlStateNormal];
self.welcomeLabel.text = [NSString stringWithFormat:NSLocalizedString(@"home_title_welcome", nil), @"John"]; //"hello %@"
self.radioButtonImageView.image = selected ? [UIImage imageNamed:@"checkedRadioButton"] : [UIImage imageNamed:@"uncheckedRadioButton"];

Now you can write

[self.buttonProceed setTitle:R.string.localizable.homeProceed forState:UIControlStateNormal];
self.welcomeLabel.text = [R.string.localizable homeTitleWelcome:@"John"];
self.radioButtonImageView.image = selected ? R.image.checkedRadioButton : R.image.uncheckedRadioButton;

Available command line options

You can add these options to customize R.objc behaviour:

  • -p (or --path): MANDATORY path to the root of the project or from where you want the scan to begin

  • -e (or --excluded): excluded dir path; all dirs within this path will be excluded; you can use -e option more than once, e.g. -e $(SRCROOT)/Pods -e $(SRCROOT)/Carthage

  • -v (or --verbose): verbose logging

  • -s (or --sysdata): for internal use only

  • -r (or --refactor): R.objc will replace all occurrences of NSLocalizedString with the correct R.string reference

  • --skip-strings: jump the strings step

  • --skip-images: jump the images step

  • --skip-themes: jump the themes step. Use this to avoid Giotto import error

  • --skip-storyboards: jump the storyboards step

  • --skip-segues: jump the segues step

What can you do?

Localizable strings

You can access localized strings with compile time checked keys usign keypath

R.string.localizable.commonWarning

The keypath is composed like this: R.string.<string_file_name>.<string_key>

If you check the documentation of the string (alt+click) you'll see the original key and all the localized values

You can access localized strings containing a string with format, passing directly parameters and obtaining the composed value

[R.string.localizable alertMessage:@"username" value2:4.7];

The methods is named like the key of the localized string with parameter 1 implicit; all other parameters are named value and numbered progressively. Formats in the string are mapped by the objects the represent (eg. %f is mapped as a double, %@ ad an id)

Images

All images will be mapped, those in an asset catalogue and those outside.

You can access by

R.image.navbarLogo

You'll get a UIImage* directly.

Storyboards

All storyboards in the bundle will be mapped in a R.storyboard.<storyboard_name> path. You'll have an

instantiateInitialViewController method and a method to instantiate a view controller for every storyboard identifier found.

Example:

[R.storyboard.main instantiateInitialViewController];
[R.storyboard.main loginViewController];

Segues

Like storyboards, in the segue object you'll find a list of all view controllers which are source of a segue. Starting from them, you can access their segues and get the segue identifier or perform segue passing source and sender objects

Example:

R.segue.myViewController.goToNextSegue.identifier // identifier of the segue
[R.segue.myViewController.goToNextSegue.identifier performWithSource:self sender:userInfo]; // perform segue

Themes

If you are using Giotto Theme Manager, R.objc will search for theme_*.plist files in your project. You can then access to all your constants and styles.

Example:

[R.theme.styles.myStyle applyTo:self]; // apply the style MyStyle to object self
R.theme.constants.COLOR_TEXT_LIGHT // reference to a constant in the theme

Troubleshooting

  1. You may want to exclude Pods and/or Carthage dirs. To do so pass: -e $(SRCROOT)/Pods -e $(SRCROOT)/Carthage

  2. R.h:2:9: Module 'Giotto' not found Add pod 'Giotto' to Podfile or pass --skip-themes parameter.

  3. Duplicate interface definition for class 'R<some-resource-name>' Check in the filesystem if there are more than one resource file with the same name: find <path-project-dir> -iname *<some-resource-name>* Replace with actual resource from Xcode output.

Contribute

We'll love contributions, fell free to fork and submit pull requests for additional generators or optimizations; for any question or idea write to team.mobile[AT]sysdata.it

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].