1

我使用了很多NSString常量,例如:

static NSString * const REAColorPlaybackBackgroundKey = @"REAColorPlaybackBackgroundKey";
static NSString * const REAColorPlaybackForegroundKey = @"REAColorPlaybackForegroundKey";

有不必要的重复,也没有简单的方法来重命名它们。Xcode 的Refactor命令在这里不起作用,Edit All in Scope也无法处理。有没有更聪明的方法来定义NSString常量?

4

1 回答 1

1

当然,尝试这样的事情:

#define STRING_CONSTANT(PREFIX, NAME, SUFFIX) static NSString *const PREFIX ## NAME ## SUFFIX = @"" #PREFIX #NAME #SUFFIX

// usage
STRING_CONSTANT(REA, ColorPlaybackBackground, Key);
STRING_CONSTANT(REA, ColorPlaybackForeground, Key);

显然,如果您愿意,您可以使用PREFIX和常量来代替参数。SUFFIX

于 2012-11-06T20:52:13.960 回答