简体   繁体   English

UIDocumentInteractionController中的“未使用表达结果”

[英]“Expression Result Unused” in UIDocumentInteractionController

Be gentle! 要温柔! I only have a vague understanding of what I am doing. 我对自己所做的事情只有模糊的了解。

I'm trying to set the Name property of UIDocumentInteractionController with hopes that it will change the file name before it is sent to another application. 我正在尝试设置UIDocumentInteractionController的Name属性,希望它可以在将文件名发送到另一个应用程序之前对其进行更改。 I'm using the following to accomplish this: 我正在使用以下方法来完成此任务:

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

I am getting an "Expression Result Unused" error on this line: 我在此行收到“表达式结果未使用”错误:

documentController.name = @"%@", soundFileName;

I'm losing my mind trying to figure this one out. 我正在迷失方向试图解决这一问题。 Any assistance is appreciated. 任何帮助表示赞赏。

Unfortunately you can't create a string like this: 不幸的是,您不能创建这样的字符串:

documentController.name = @"%@", soundFileName;

@"%@" is a literal NSString , but the compiler won't do any formatting/replacement for you. @"%@"是文字NSString ,但是编译器不会为您做任何格式化/替换。 You must explicitly make a call to one of the string constructor methods: 您必须显式调用字符串构造函数方法之一:

documentController.name = [NSString stringWithFormat:@"%@", soundFileName];

In this case, though, since soundFileName is itself an NSString , all you have to do is assign: 但是,在这种情况下,由于soundFileName本身就是NSString ,所以您要做的就是分配:

documentController.name = soundFileName;

The warning you're getting is the compiler saying to you that the bit after the comma (where you refer to soundFileName ) is being evaluated and then discarded, and is that really what you meant to do? 您得到的警告是编译器soundFileName ,对逗号(您指的是soundFileName )后的位进行了评估,然后将其丢弃,那真的是您的意思吗?

In C, and therefore ObjC, the comma is an operator that can separate statements; 在C中,因此在ObjC中,逗号是可以分隔语句的运算符; each is evaluated separately. 分别进行评估。 So this line where you're getting the warning could be re-written: 因此,您收到警告的这一行可能会被重写:

documentController.name = @"%@";
soundFileName;

As you can see, the second line does nothing at all. 如您所见,第二行根本不执行任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM