2012-11-06 32 views
1

我用了很多的NSString常量,如:重命名的NSString常量

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

有不必要的口是心非,沒有簡單的方法來重命名。 Xcode的重構命令在這裏不起作用,編輯全部在範圍也無法處理它。有沒有更明智的方法來定義NSString常量?

+0

您可以隨時使用'#define'。 –

+0

解決方法是使用另一個IDE,例如AppCode – brainray

回答

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); 

很明顯,你可以讓PREFIXSUFFIX常量而不是參數,如果你願意。