Indenting Continuation Lines in Xcode

Can I get Xcode’s automatic indentation to indent continuation lines?

I want:

  • Programmatically change the height and width of a UIImageView Xcode Swift
  • libcurl linker error on Xcode5 but working fine on Xcode 4.6
  • iPhone 6 Plus resolution confusion: Xcode or Apple's website? for development
  • How to programmatically display version/build number of target in iOS app?
  • Lion + Xcode 3.2.3 starting problem
  • Disable autolayout constraint error messages in debug console output in Xcode
  • BOOL someLongVariableName = someLongValue
        | someOtherLongValue
        | moreLongValues
    
    BOOL someOtherLongVariableName =
        someEvenLongerValue;
    
    [someLongVariableName
        performSomeAction:someLongArgument]
    

    I currently get:

    BOOL someLongVariableName = someLongValue
    | someOtherLongValue
    | moreLongValues
    
    BOOL someOtherLongVariableName =
    someEvenLongerValue;
    
    [someLongVariableName
     performSomeAction:someLongArgument]
    

    To be clear:

    • I’m using explicit line breaks not automatic wrapping.
    • I want the correct indent while editing and immediately after pressing return, not after running an external program (like uncrustify).

    2 Solutions Collect From Internet About “Indenting Continuation Lines in Xcode”

    I ended up integrating uncrustify to partially get what I wanted. (Case 3 is still off, though.)

    Xcode integration

    To get Xcode to indent the code automatically, I’ve created an “Aggregate” target with a “Run Script” phase:

    find . -name '*.[mh]' -print0 \
        | xargs -0 git diff-index HEAD -- | grep -v "D\t" | cut -c100- \
        | xargs uncrustify -l OC --replace --no-backup -c uncrustify.cfg
    

    This runs uncrustify on all files that are marked as changed in git. I’ve added my app target as a dependency to the format target, so it only formats if compilation succeeds. (Important, since uncrustify would be confused by broken syntax.) Finally, I’ve added the format target to my scheme, so every build starts a format. Xcode usually reloads the formatted file on its own.

    The relevant setting my uncrustify.cfg is indent_continue = 4.

    Problems

    Undo information is lost when Xcode reloads the formatted file. I could run the script from a git pre-commit hook, but I prefer quicker results.

    Another downside is that Objective-C support in uncrustify isn’t perfect, but there seems to be no alternative. (Maybe clang-format someday?)

    Or try xcode-preferences-text editing-indentation:
    check syntax aware indenting, check automatic indenting for “Return”.