我发现自己浪费了很多时间处理XCode的自动缩进,我不得不问我的设置中是否有错误?基本上,如果我花时间在方法中缩进代码,然后复制整个方法并粘贴它,新粘贴的方法不会保留我应用于原始的任何空白区域...
例如,下面是截图,其中顶部方法我缩进一个数组中的所有对象,使他们一字排开正确......然后,我选择了整个方法,复制和粘贴,你可以看到下面的方法有压痕所有弄乱.

我正在使用Xcode 4.4.1,这是我的设置:

And*_*iot -4
按预期工作。
\n\n\xe2\x80\xa6Objects:并且forKeys:应该对齐,因为它们构成同一方法签名的一部分。
如果您使用新的对象文字语法,那么格式化代码可能会更容易:
\n\n- (int)minBrokenPieces {\n NSDictionary *mapping = [NSDictionary dictionaryWithObjects:@[@"3", @"4", @"4", @"5", @"6", @"7", @"8"]\n forKeys:[Note types]];\n [(NSString *)mapping[self.note.type] integerValue];\n}\nRun Code Online (Sandbox Code Playgroud)\n\n至于代码本身,在一个地方定义这些常量而在其他地方定义注释类型似乎有点危险。另外,既然 NSNumbers 就足够了,为什么还要使用字符串呢?
\n\n(此代码假设该函数仅从一个线程调用)。
\n\n- (int)minBrokenPieces {\n static NSDictionary *mappings;\n if (!mappings) {\n mappings = @{\n noteType1 : @3,\n noteType2 : @4,\n noteType3 : @4,\n noteType4 : @5,\n noteType5 : @6,\n noteType6 : @7,\n noteType7 : @8,\n };\n }\n NSAssert(mappings[self.note.type] != nil, @"Used a note type for which there is no minBrokenPieces defined");\n return [mappings[self.note.type] intValue];\n}\nRun Code Online (Sandbox Code Playgroud)\n