• Stars
    star
    194
  • Rank 200,219 (Top 4 %)
  • Language
    Shell
  • Created about 12 years ago
  • Updated about 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple automatic code formatter for Xcode

XCODE FORMATTER

Why a code formatter

A common problem with large iOS projects is the lack of support for a shared set of formatting rules. This leads over the time to unreadable and hard to maintain sources files.

Xcode Formatter uses uncrustify to easily format your source code as your team exactly wants it to be!

Simply add the CodeFormatter directory in your Xcode project to get :

  • Xcode shortcut-based code formatting: a shortcut to format modified sources in the current workspace
  • automatic code formatting: add a build phase to your project to format current sources when application builds
  • all sources formatting: format all your code with one command line
  • your formatting rules shared by project: edit and use a same configuration file with your project dev team

  1. How to setup the code formatter for your project

Install uncrustify

The simplest way is to use brew:

$ brew install uncrustify

To install brew:

$ ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"

Check that uncrustify is located in /usr/local/bin/

$ which uncrustify

If your uncrustify version is lower than 0.60, you might have to install it manually since modern Objective-C syntax has been added recently, see this post : http://stackoverflow.com/questions/11862964/uncrustify-doesnt-support-for-the-new-objective-c-syntax-of-llvm-4-0/14202765#14202765

Add CodeFormatter directory beside your .xcodeproj file

CodeFormatter directory location

Check that your Xcode application is named "Xcode" (default name)

You can see this name in the Applications/ directory (or your custom Xcode installation directory). Be carefull if you have multiple instances of Xcode on your mac: ensure that project's one is actually named "Xcode"!

(Why this ? This name is used to find currently opened Xcode files. See CodeFormatter/Uncrustify_opened_Xcode_sources.workflow appleScript).

Install the automator service Uncrustify_opened_Xcode_sources.workflow

Copy this file to your ~/Library/Services/ folder (create this folder if needed).

Be careful : by double-clicking the .workflow file, you will install it but the file will be removed! Be sure to leave a copy of it for other users.

  1. How to format opened files when building the project

Add a build phase "run script" containing the following line:

sh CodeFormatter/scripts/formatOpenedSources.sh

Add build phase

  1. How to format opened files with a shortcut

Add a shortcut to the Uncrustify_opened_Xcode_sources service

Go to Xcode > Services > Services preferences :

Create service shortcut

And set your shortcut :

Choose service shortcut

  1. How to format files in command line

To format currently opened files, use formatOpenedSources.sh:

$ sh CodeFormatter/scripts/formatOpenedSources.sh

To format all files, use formatAllSources.sh:

$ sh CodeFormatter/scripts/formatAllSources.sh PATH

PATH must be replaced by your sources path.

  1. How to change formatter’s rules

Edit CodeFormatter/uncrustify_objective_c.cfg

You can use UniversalIndentGUI (http://universalindent.sourceforge.net/) to simplify edition.

  1. FAQ

When formatting the current sources, an unknown error occurs and shows my code. What can I do?

Uncrustify (version 0.59) does not handle apple new literals for creating NSDictionary and NSArray like:

NSDictionary *dictionary = @{@0 : @"red",
 							 @1 : @"green",
 							 @2 : @"blue"};

Until a new version of uncrustify fixes this issue, you can use the old way with those literals:

NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"red", @1, 
                                                                       @"green", @2, 
                                                                       @"blue", @3, 
                                                                       nil];

I want to have a single configuration file for all my Xcode projects, is it possible?

Yes, everything is possible. Just move your configuration file to your home directory: '~/.uncrustify//uncrustify_objective_c.cfg' and remove 'CodeFormatter' directory from your project. If the configuration file is not found in project directory, this global file is used.

More Repositories

1

sonar-objective-c

Sonar Plugin for Objective C
Java
517
star
2

RoboSpice-samples

All samples of the RoboSpice library.
Java
215
star
3

kubernetes-icons

[obsolete] Set of icons for Kubernetes diagrams, has been merged into official k8s repo!!
214
star
4

AppResizer

Check if your iOS app is responsive.
Shell
70
star
5

USI2011_BillionUserChallenge

Billion user challenge @ USI 2011
25
star
6

tezos-academy

Learn to code Tezos Smart Contract the fun way
TypeScript
22
star
7

java-sql-dsl

A Java SQL DSL
Java
21
star
8

OpenTezos

The complete encyclopedia of Tezos
HTML
16
star
9

Tezos-Land-FA2-NFT-Boilerplate

TypeScript
12
star
10

VIO

Visual Inspection Orchestrator is a modular framework made to ease the deployment of VI usecases
Python
12
star
11

tezos-link

Your gateway to the Tezos network
TypeScript
12
star
12

sample-sonar-objective-c

Skeleton showing howto setup / structure an objective-c project for analysing with the sonar objective-c plugin
Objective-C
9
star
13

ddui

Airflow's plugin for Data Science pipeline visualisation
Python
8
star
14

ddapi

Python
6
star
15

awscli-saml-sso

awscli_saml_sso is a command line tool that aims to get temporary credentials from SAML identity provider in order to authenticate to awscli.
Python
6
star
16

terraform-provider-mattermost

Go
5
star
17

appaloosa-android-sdk

Java
5
star
18

epic-legacy-code-challenge

JavaScript
5
star
19

worker-decorator

Kotlin
5
star
20

net_crusher

Erlang
4
star
21

chti.octo.com

HTML
3
star
22

tdd-on-auth0-scripts

How to TDD on Auth0 scripts
JavaScript
2
star
23

provider-jet-scaleway

Go
2
star
24

ios-trackers-detect

Script to detect iOS tracker libraries from an IPA file
Python
2
star
25

Formation-MLOps-2

Python
2
star
26

toulouse.octo.com

HTML
2
star
27

refacard_indus_datascience

The refcard content used to describe patterns and technics we believe that help the industrialization process of Datascience project
1
star
28

bdacore

Jupyter Notebook
1
star
29

octofacebook

Ruby
1
star
30

appaloosa-client

Java client to upload ipa and apk file to Appaloosa
1
star
31

libkoca

Description de libkoca
Shell
1
star
32

octo-integration-rails-plugin

Rails plugin containing OpenId authentication support
JavaScript
1
star
33

LearnedStuff

A manifest for datascience
1
star
34

appaloosa-android-sdk-sample

Sample android application using appaloosa-android-sdk
Java
1
star
35

azuread-msgraph

Ansible Collection Azure Active Directory (MS Graph)
Python
1
star
36

Formation-MLOps-1

Makefile
1
star
37

OTPieChart

Objective-C
1
star
38

Formation-MLOps-3

Python
1
star
39

rustig

Learning Rust by writting a git clone
Rust
1
star
40

byod

Bring Your Own Device Manifesto
Ruby
1
star
41

salle-de-sport-kotlin

Implémentation de "la salle de sport" d'Arnaud Lemaire, en Kotlin. Sert de point de référence concernant certaines pratiques (DDD, CQRS, constructeurs nommés, lisibilité, tests, etc), afin de pouvoir s'y référer, mais aussi pour s'en servir de support pédagogique lors de dojos et autres formations.
Kotlin
1
star