2011-10-25 4 views
5

Tutte le mie chiamate di NSLocalizedString hanno nil come secondo parametro, perché non uso alcun commento. Ma odio ripetermi. Ora mi chiedo se va bene definire una macro come LSSTRING (str) che chiama NSLocalizedString (str, nil), e se sì, come?Macro per NSLocalizedString

risposta

10

È possibile. Aggiungi la seguente macro all'intestazione precompilata. vale a dire., in {} Nome progetto file di -Prefix.pch

#define LSSTRING(str) NSLocalizedString(str, nil) 
+4

Un problema con questo approccio è che genstrings si aspetta di trovare una stringa per il commento, e darà un errore come questo: 'Bad entry in file ... (line = #): Argument non è una stringa letterale. –

+3

In Xcode, basta fare un find/replace in questo modo: Trova: LSSTRING \ ((@ \" \ w + \ ") \) Sostituisci: NSLocalizedString \ (\ 1, \ 1 \) – Damon

2

im utilizzando

#define _(format, ...) [[NSBundle mainBundle] localizedStringForKey: [NSString stringWithFormat:@"%@", [NSString stringWithFormat:format, ##__VA_ARGS__]] value:@"" table:nil] 
+1

Perché il primo' stringWithFormat: '? –