Сохранение NSAttributedString с NSTextAttachment в файл. Как?

у меня естьNSTextView, который может содержать форматированный текст или форматированный текст с изображением в видеNSTextAttachment, Вот как я добавляю вложение:

NSImage *image = [NSImage imageNamed:@"image"];

NSTextAttachmentCell *attachmentCell =[[NSTextAttachmentCell alloc] initImageCell:image];
NSTextAttachment *attachment =[[NSTextAttachment alloc] init];
[attachment setAttachmentCell: attachmentCell ];
NSAttributedString *attributedString =[NSAttributedString  attributedStringWithAttachment: attachment];
[[aTextView textStorage] beginEditing];
if ([aTextView shouldChangeTextInRange:NSMakeRange([aTextView selectedRange].location, 0) replacementString:@""]) {
    [[aTextView textStorage] insertAttributedString:attributedString atIndex:[aTextView selectedRange].location];
    [aTextView didChangeText];
}
[[aTextView textStorage] endEditing];

мой-fileWrapperOfType:error: метод:

- (NSFileWrapper *)fileWrapperOfType:(NSString *)typeName error:(NSError *__autoreleasing *)outError
{
    NSRange documentRange = NSMakeRange(0, [[[WindowController aTextView] textStorage] length]);
    NSTextStorage *text = [[WindowController aTextView] textStorage];

    NSFileWrapper *resultWrapper = nil;
    if ([typeName compare:@"public.rtf"] == NSOrderedSame) {
        resultWrapper = [[NSFileWrapper alloc] initRegularFileWithContents:[text RTFFromRange:documentRange documentAttributes:[NSDictionary dictionaryWithObjectsAndKeys:NSRTFTextDocumentType, NSDocumentTypeDocumentAttribute, nil]]];
    }
    else if ([typeName compare:@"com.apple.rtfd"] == NSOrderedSame) {
        resultWrapper = [text RTFDFileWrapperFromRange:documentRange documentAttributes:[NSDictionary dictionaryWithObjectsAndKeys:NSRTFDTextDocumentType, NSDocumentTypeDocumentAttribute, nil]];
    }
    return resultWrapper;
}

Но когда я сохраняю RTFD, все вложения теряются. Пожалуйста помоги. Что мне не хватает?

Ответы на вопрос(1)

Ваш ответ на вопрос