1

穏やかな!私は自分が何をしているのか漠然としか理解していません。

別のアプリケーションに送信される前にファイル名が変更されることを期待して、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];

次の行で「Expression Result Unused」エラーが発生します。

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

私はこれを理解しようとして気が狂っています。任意の支援をいただければ幸いです。

4

1 に答える 1

1

残念ながら、次のような文字列を作成することはできません。

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

@"%@"はリテラルNSStringですが、コンパイラはフォーマットや置換を行いません。文字列コンストラクター メソッドのいずれかを明示的に呼び出す必要があります。

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

ただし、この場合、soundFileNameそれ自体が であるためNSString、次のように代入するだけです。

documentController.name = soundFileName;

あなたが得ている警告は、コンマの後のビット(あなたが参照する場所soundFileName)が評価されてから破棄されているとコンパイラが言っていることです。それは本当にあなたが意図したことですか?

C、つまり ObjC では、カンマはステートメントを区切る演算子です。それぞれ個別に評価されます。したがって、警告が表示されるこの行は書き直すことができます。

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

ご覧のとおり、2 行目は何もしません。

于 2012-03-08T20:15:47.507 に答える