1

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. 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.

1 Answers1

1

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. 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:

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?

In C, and therefore ObjC, the comma is an operator that can separate statements; 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.

jscs
  • 63,694
  • 13
  • 151
  • 195
  • Thanks for the informative answer! Unfortunately the name of the file being sent to the other apps is not being changed, however. Unless something strikes you as obvious, I'll save it for another question after doing some searching around. – user1257826 Mar 08 '12 at 22:25
  • Inspect `soundFileName` and the other variables from which you create that using `NSLog`: `NSLog(@"%@, %@, %@", suffixName, currentNote.soundFile, soundFileName);` to make sure that they are what you expect them to be. – jscs Mar 09 '12 at 06:56
  • I'm trying to do the same - and the name does not change. I can change the UTI but not the name ;( – slott Sep 04 '12 at 07:09