为什么Xcode的自动缩进很糟糕?我怎么能做得更好?

我发现自己浪费了很多时间来处理XCode的自动缩进,我必须询问我的设置中是否有错误?基本上如果我花时间缩进方法中的代码,然后复制整个方法并将其粘贴,则新粘贴的方法不会保留我应用于原始代码的任何空格

例如,这里是一个截图,其中顶部的方法我缩进了数组的所有对象,使其正确排列…然后我选择了整个方法,复制和粘贴,您可以看到下面的方法有缩进所有弄乱.

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

解决方法

按预期工作.

…对象:和forKeys:应该对齐,因为它们是相同方法签名的一部分.

如果您使用新的对象字面语法,则可能会更容易格式化代码

- (int)minbrokenPieces {
   NSDictionary *mapping = [NSDictionary dictionaryWithObjects:@[@"3",@"4",@"5",@"6",@"7",@"8"]
                                                       forKeys:[Note types]];
  [(Nsstring *)mapping[self.note.type] integerValue];
}

对于代码本身,在一个地方定义这些常量,其他地方的笔记类型似乎有点危险.另外,为什么要使用字符串,当NSNumbers就足够了?

(此代码假定此函数仅从一个线程调用).

- (int)minbrokenPieces {
    static NSDictionary *mappings;
    if (!mappings) {
        mappings = @{
            noteType1  : @3,noteType2  : @4,noteType3  : @4,noteType4  : @5,noteType5  : @6,noteType6  : @7,noteType7  : @8,};
    }
    NSAssert(mappings[self.note.type] != nil,@"Used a note type for which there is no minbrokenPieces defined");
    return [mappings[self.note.type] intValue];
}

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...