[英]“Expression Result Unused” in UIDocumentInteractionController
要溫柔! 我對自己所做的事情只有模糊的了解。
我正在嘗試設置UIDocumentInteractionController的Name屬性,希望它可以在將文件名發送到另一個應用程序之前對其進行更改。 我正在使用以下方法來完成此任務:
UIDocumentInteractionController *documentController;
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSURL *soundFileURL = [NSURL fileURLWithPath:[docDir stringByAppendingPathComponent:
[NSString stringWithFormat: @"%@/%@", kDocumentNotesDirectory, currentNote.soundFile]]];
NSString *suffixName = @"";
if (self.mediaGroup.title.length > 10) {
suffixName = [self.mediaGroup.title substringToIndex:10];
}
else {
suffixName = self.mediaGroup.title;
}
NSString *soundFileName = [NSString stringWithFormat:@"%@-%@", suffixName, currentNote.soundFile];
documentController = [UIDocumentInteractionController interactionControllerWithURL:(soundFileURL)];
documentController.delegate = self;
[documentController retain];
documentController.UTI = @"com.microsoft.waveform-audio";
documentController.name = @"%@", soundFileName; //Expression Result Unused error here
[documentController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
我在此行收到“表達式結果未使用”錯誤:
documentController.name = @"%@", soundFileName;
我正在迷失方向試圖解決這一問題。 任何幫助表示贊賞。
不幸的是,您不能創建這樣的字符串:
documentController.name = @"%@", soundFileName;
@"%@"
是文字NSString
,但是編譯器不會為您做任何格式化/替換。 您必須顯式調用字符串構造函數方法之一:
documentController.name = [NSString stringWithFormat:@"%@", soundFileName];
但是,在這種情況下,由於soundFileName
本身就是NSString
,所以您要做的就是分配:
documentController.name = soundFileName;
您得到的警告是編譯器soundFileName
,對逗號(您指的是soundFileName
)后的位進行了評估,然后將其丟棄,那真的是您的意思嗎?
在C中,因此在ObjC中,逗號是可以分隔語句的運算符; 分別進行評估。 因此,您收到警告的這一行可能會被重寫:
documentController.name = @"%@";
soundFileName;
如您所見,第二行根本不執行任何操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.