Skip to content

A script for formatting the Objective-C codes in XCode

License

Notifications You must be signed in to change notification settings

suhugo/objc-formatter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Objc Formatter

A simple way for formatting the Objective-C codes in XCode

Prerequisites

Install uncrustify

brew install uncrustify

Config uncrustify

Download uncrustify_obj_c.txt

mv uncrustify_obj_c.txt ~/.uncrustify_obj_c.cfg

Or you can use your own config file.

How to use it

In the Build Phases section of your project target, add a new Run Script phase before the Compile Sources step.

The script should be

function format_dir(){
    for element in `ls $1`
    do
        dir_or_file=$1"/"$element
        if [ -d $dir_or_file ]
        then
            format_dir $dir_or_file
        else
            file=$element
            if [ "${file##*.}"x = "h"x ] || [ "${file##*.}"x = "m"x ] || [ "${file##*.}"x = "mm"x ];then
                uncrustify  -c ~/.uncrustify_obj_c.cfg --no-backup -l OC $dir_or_file
            fi
        fi
    done
}

format_dir "${SRCROOT}/path/to/your/objc/code/"

Change the path to your objc code's folder

If you have another objc code's folder to format, just call another format_dir().

e.g.

Now build your project, and the objc codes will be auto formatted.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

A script for formatting the Objective-C codes in XCode

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages