【问题标题】:Automatic column align along colons in Xcode and Objective C在 Xcode 和 Objective C 中自动沿冒号对齐列
【发布时间】:2014-06-29 05:22:49
【问题描述】:

是否有宏或首选项设置可以自动沿 Xcode 中的列和冒号对齐方法参数?

基本上是转这个的捷径:

[object methodWithParam:theParam another:theOtherValue something:theSomethingValue else:theElseValue];

自动进入这个:

[object methodWithParam:theParam 
                another:theOtherValue 
              something:theSomethingValue 
                   else:theElseValue];

是否可以通过代码完成来实现此功能?换句话说,当我完成一个方法时,它会自动将格式包装成这种样式?那么预先存在的代码呢?我可以将插入符号放在方法中,按键盘快捷键并自动格式化参数吗?

【问题讨论】:

    标签: objective-c code-formatting


    【解决方案1】:

    我认为您正在尝试完成以下操作

    [object methodWithParam:theParam another:theOtherValue something:theSomethingValue else:theElseValue];
    

    变成更易读的东西,例如

    [object methodWithParam:theParam
                    another:theOtherValue
                  something:theSomethingValue
                       else:theElseValue];
    

    这可以通过在每个伪参数之前按下return 键来完成。例如,在显示 <return> 的位置按回车键。

    [object methodWithParam:theParam <return>another:theOtherValue <return>something:theSomethingValue <return>else:theElseValue];
    

    如果执行得当,冒号应该对齐。

    [object methodWithParam:theParam<return>
                    another:theOtherValue<return>
                  something:theSomethingValue<return>
                       else:theElseValue];
    

    【讨论】:

    • 您也可以将未对齐的线条剪切并粘贴到位。 (前提是每个 arg 后面都有一个换行符)
    • 或者只选择文本块并从编辑器菜单中选择重新缩进。 (我认为就是这样。无论如何它都是 control-i。)检查 Xcode 首选项以确保相关的缩进选项也已打开。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-05
    相关资源
    最近更新 更多