我使用的是全部基於塊的mailcore2。他們通常定義,像這樣如何解決NSException格式使用非字符串文字的安全問題
SomeMailCoreOp *op = [session getOp];
[op start:^(NSError* error, id result) {
if (error) {
// handle error code
}
}];
所以我想要做的基本上是簡單地拋出一個NSException
每次遇到一個錯誤的時間..所以我可以在我的代碼庫別的地方抓住它的操作。所以我創造了NSError
類別:
@implementation NSError (Addons)
-(NSString *)description {
return [NSString stringWithFormat:@"%@ - %@",
[self localizedDescription], [self localizedFailureReason]];
}
@end
,這是我想一般處理錯誤:
SomeMailCoreOp *op = [session getOp];
[op start:^(NSError* error, id result) {
if (error) {
[NSException raise:@"failure" format:[error description]];
}
}];
我想這是有道理的由於在documentation爲NSException他們得到了這對於format
:
格式,人類可讀的消息字符串(即,異常 原因)與轉換規格爲可變參數的是 後續。
format string is not a string literal (potentially insecure)
我怎麼解決這個問題:
但我當我做上述總能得到這個編譯器警告?